表格内容完全对齐

表格内容完全对齐

我需要完全证明表格内容,例如 RSCA、RR1、RR2 等值。有没有办法在表格中提供值充分合理水平方向不是左对齐例如我们提供的\begin{tabular}{|l|l|l|}左对齐内容。

代码如下所示:

\def\arraystretch{1.3}%
\begin{table}[h]
\centering
\caption{Values of Dispersion Constant ($R$)}
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{1}{|c|}{\textbf{Algorithm}} & \multicolumn{2}{ c|}{{\boldmath\textbf{Dispersion Constant ($R$)}}}\\
\hline
& \multicolumn{1}{ c|}{\textbf{M=16}} & \multicolumn{1}{ c|}{\textbf{M=32}}\\ \hline 
SCA & R\textsubscript{SCA} = 123 & R\textsubscript{SCA} = 123 \\\hline
\justifying
MCMA & R\textsubscript{R} = 2.55 and R\textsubscript{I} = 2.55  & R\textsubscript{R} = 2.55 and R\textsubscript{I} = 2.55\\
\hline 
\multirow{2}*{DD-MCMA} & R\textsubscript{R1} = 0.75 and R\textsubscript{R2} = 2.55 & R\textsubscript{R1} = 0.75 and R\textsubscript{R2} = 2.55 \\
& R\textsubscript{I1} = 0.75 and R\textsubscript{I2} = 2.55 & R\textsubscript{I1} = 0.75 and R\textsubscript{I2} = 2.55 \\
\hline
\end{tabular}
\end{table}

我想让这部分代码看起来水平对齐

SCA & R\textsubscript{SCA} = 123 & R\textsubscript{SCA} = 123 \\\hline
\justifying
MCMA & R\textsubscript{R} = 2.55 and R\textsubscript{I} = 2.55  & 
R\textsubscript{R} = 2.55 and R\textsubscript{I} = 2.55\\
\hline 
\multirow{2}*{DD-MCMA} & R\textsubscript{R1} = 0.75 and R\textsubscript{R2} 
= 2.55 & R\textsubscript{R1} = 0.75 and R\textsubscript{R2} = 2.55 \\
& R\textsubscript{I1} = 0.75 and R\textsubscript{I2} = 2.55 & 
R\textsubscript{I1} = 0.75 and R\textsubscript{I2} = 2.55 \\
\hline

答案1

编辑1(回复评论):

列类型的解释(后的代码tabular):

  1. >{...}可以告诉 LaTeX 做一些事情<{...}用一些东西写单元格内容;您需要array这些选项的包
  2. 告诉S[table-format=1.2]LaTeX 您有 1 个整数和 2 个小数,需要在小数点处对齐(siunitx需要包)
  3. @{something}可以插入something而不是列间空格(array包)
  4. !{something}可以插入something而不是|(始终查看array包装)。

\documentclass{article}
\usepackage{array}
\renewcommand{\arraystretch}{1.3}
\usepackage{siunitx}
\usepackage{caption}
\usepackage{amsmath}

\begin{document}
    \begin{table}[h]
        \centering\footnotesize
        \caption{Values of Dispersion Constant ($R$)}
        \begin{tabular}{
                |l|
                >{$}l<{$}@{${}={}$}S[table-format=1.2]
                !{and}
                >{$}l<{$}@{${}={}$}S[table-format=1.2]|
                >{$}l<{$}@{${}={}$}S[table-format=1.2]
                !{and}
                >{$}l<{$}@{${}={}$}S[table-format=1.2]|
            }
            \hline
            \multicolumn{1}{|c|}{\textbf{Algorithm}} & \multicolumn{8}{ c|}{{\boldmath\textbf{Dispersion Constant ($R$)}}}\\
            \hline
            & \multicolumn{4}{ c|}{\boldmath $M=16$} & \multicolumn{4}{ c|}{\boldmath $M=32$}\\ \hline 
            SCA & \multicolumn{4}{c|}{$R_{\text{SCA}}=123$} & \multicolumn{4}{c|}{$R_{\text{SCA}}=123$} \\\hline
            MCMA & R_{\text{R}} & 2.55 & R_{\text{I}} & 2.55  & R_{\text{R}} & 2.55 & R_{\text{I}} & 2.55\\
            \hline 
            DD-MCMA & R_\text{{R1}} & 0.75 & R_{\text{R2}} & 2.55 & R_{\text{R1}} & 0.75 & R_{\text{R2}} & 2.55 \\
            & R_{\text{I1}} & 0.75 & R_{\text{I2}} & 2.55 & R_{\text{I1}} & 0.75 & R_{\text{I2}} & 2.55 \\
            \hline
        \end{tabular}
    \end{table}
\end{document}

在此处输入图片描述

编辑 2(这是 OP 想要的,不是我喜欢的):

如果您想要 Word 对齐,请使用\hfill

\documentclass{article}
\usepackage{array}
\usepackage{siunitx}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{multirow}

\begin{document}
\def\arraystretch{1.3}%
\begin{table}[h]
    \centering
    \caption{Values of Dispersion Constant ($R$)}
    \begin{tabular}{|l|l|l|}
        \hline
        \multicolumn{1}{|c|}{\textbf{Algorithm}} & \multicolumn{2}{ c|}{{\boldmath\textbf{Dispersion Constant ($R$)}}}\\
        \hline
        & \multicolumn{1}{ c|}{\textbf{M=16}} & \multicolumn{1}{ c|}{\textbf{M=32}}\\ \hline 
        SCA & R\textsubscript{SCA} \hfill = \hfill 123 & R\textsubscript{SCA} \hfill = \hfill 123 \\\hline
        MCMA & R\textsubscript{R} \hfill = \hfill 2.55 \hfill and R\textsubscript{I} \hfill = \hfill 2.55  & R\textsubscript{R} \hfill = 2.55 \hfill and \hfill R\textsubscript{I} \hfill = \hfill 2.55\\
        \hline 
        \multirow{2}*{DD-MCMA} & R\textsubscript{R1} \hfill = \hfill 0.75 \hfill and \hfill R\textsubscript{R2} \hfill = \hfill 2.55 & R\textsubscript{R1} \hfill = \hfill 0.75 \hfill and \hfill R\textsubscript{R2} \hfill = \hfill 2.55 \\
        & R\textsubscript{I1} \hfill = \hfill 0.75 \hfill and \hfill R\textsubscript{I2} \hfill = \hfill 2.55 & R\textsubscript{I1} \hfill = 0.75 \hfill and \hfill R\textsubscript{I2} \hfill = \hfill 2.55 \\
        \hline
    \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容