Problem with formatting tables in LaTeX

I want to create two tables with the same column width. Both tables consist of 6 rows and 3 columns. In both tables, rows 1 and row 4 are explanatory and should be expanded in all columns. In the first table, rows 2, 3, 5, and 6 should have three columns of the same width. In the second table, rows 2 and 3 should have 2 columns of the same width, and rows 5 and 6 should have three columns of the same width.

This is how I made the first table:

    \begin{table}[h]
        \caption{Distribution of mappings for the SLA parameter $\pi$.}
        \label{tab:distPi} \centering
        \begin{tabular*}{0.45\textwidth}{@{\extracolsep{\fill}}|c|c|c|}
            \hline
                \multicolumn{3}{|c|}{\textbf{Name of the SLA parameter $\pi$}} \\
            \hline
                \emph{Cost} & \emph{Charge} & \emph{Rate} \\
            \hline
                15\% & 15\% & 40\% \\
            \hline
            \hline
                \multicolumn{3}{|c|}{\textbf{Unit of the SLA parameter $\pi$}} \\
            \hline
                \emph{USD} & \emph{GBP} & \emph{YPI} \\
            \hline
                38\% & 2\% & 40\% \\
            \hline
        \end{tabular*}
        \vspace{-0.3cm}
    \end{table}

and this is how I made the second table:

    \begin{table}[h]
        \caption{Distribution of mappings for the SLA parameter $\mu$.}
        \label{tab:distMu} \centering
        \begin{tabular*}{0.45\textwidth}{@{\extracolsep{\fill}}|c|c|c|c|c|c|}
            \hline
                \multicolumn{6}{|c|}{\textbf{Name of the SLA parameter $\mu$}} \\
            \hline
                \multicolumn{3}{|c|}{\emph{MemoryConsumption}} & \multicolumn{3}{|c|}{\emph{Consumption}} \\
            \hline
                \multicolumn{3}{|c|}{70\%} & \multicolumn{3}{|c|}{30\%} \\
            \hline
            \hline
                \multicolumn{6}{|c|}{\textbf{Unit of the SLA parameter $\mu$}} \\
            \hline
                \multicolumn{2}{|c|}{\emph{Mbit}} & \multicolumn{2}{|c|}{\emph{Gbit}} & \multicolumn{2}{|c|}{\emph{Tbit}} \\
            \hline
                \multicolumn{2}{|c|}{5\%} & \multicolumn{2}{|c|}{55\%} & \multicolumn{2}{|c|}{40\%} \\
            \hline
        \end{tabular*}
        \vspace{-0.3cm}
    \end{table}

However, formatting is not very good. Unfortunately, I can’t show the screenshot because my reputation is less than 10.

- , ? , . . 90% .

+3
1

, . , , , vline hlines , \begin {tabular *}, . , , , , vline. , , {tabular}, width, {tabular *}. , ( [h]), , , , {tabular}.

+1
source

Source: https://habr.com/ru/post/1779211/


All Articles