表格内容大于其余文本,且不居中

表格内容大于其余文本,且不居中

我写了以下代码来插入表格。但有两个问题:

  • \scriptsize即使在 12 磅文档中使用,内容也比其余文本更大
  • 内容似乎向左对齐,但我希望它们居中

MWE 是:

\documentclass[12pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=1.50in, right=1.00in, top=1.25in, bottom=1.00in]{geometry}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{lipsum}
\begin{document}
    \lipsum[1]
    \begin{table}[!htbp]
        \caption{Table showing mapping  of sequences }
        \label{Table_CE1}
        \centering{
            \resizebox{\textwidth}{!}{%
                \scriptsize  \begin{tabular}{@{}lll@{}}
                    \toprule
                    \begin{tabular}[c]{@{}l@{}}{Original}\\   {Symbol}\end{tabular} & \begin{tabular}[c]{@{}l@{}}{Mapped Symbol}\\ {with different}\\ Real /Imaginary Axis\end{tabular} & \begin{tabular}[c]{@{}l@{}}{Mapped Symbol}\\ {with different}\\ Real and Imaginary axis\end{tabular}\\ \midrule
                    a & \begin{tabular}[c]{@{}l@{}} Equal real parts (c or f)\\Equal imaginary parts (f or e )\end{tabular} & \begin{tabular}[c]{@{}l@{}} c or e\\ d or f \end{tabular}\\\\
                    b & \begin{tabular}[c]{@{}l@{}} Equal real parts (d or e)\\Equal imaginary parts (d or c )\end{tabular} & \begin{tabular}[c]{@{}l@{}} d or f \\c or e  \end{tabular}\\
                    \bottomrule

            \end{tabular}}
        }
    \end{table}
    \lipsum[2]
\end{document}

答案1

表格的自然大小比文本宽度窄,因此当您调整大小时,字体大小都会变大,无论您将其设置得多小。

想想

\resizebox{\textwidth}{!}{\tiny A}

即使声明为,也会产生非常大的“A” \tiny

  1. 切勿应用于\resizebox表格。

  2. 尽可能使用自然尺寸。

  3. \centering不是一个带参数的命令。

这是一个修复版本,我使用它是\makecell为了方便嵌套tabular

\documentclass[12pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=1.50in, right=1.00in, top=1.25in, bottom=1.00in]{geometry}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{lipsum}
\begin{document}

\lipsum[1]

\begin{table}[!htbp]
\caption{Table showing mapping  of sequences }
\label{Table_CE1}
\centering

\begin{tabular}{@{}lll@{}}
\toprule
\makecell[l]{Original \\ Symbol} &
  \makecell[l]{Mapped Symbol\\ with different\\ Real /Imaginary Axis} &
  \makecell[l]{Mapped Symbol\\ with different\\ Real and Imaginary axis}\\
\midrule
$a$ & \makecell[l]{Equal real parts ($c$ or $f$)\\Equal imaginary parts ($f$ or $e$)} &
  \makecell[l]{$c$ or $e$\\ $d$ or $f$}\\
\addlinespace
b & \makecell[l]{Equal real parts ($d$ or $e$)\\Equal imaginary parts ($d$ or $c$)} &
  \makecell[l]{$d$ or $f$ \\$c$ or $e$} \\
\bottomrule
\end{tabular}

\end{table}

\lipsum[2]

\end{document}

在此处输入图片描述

为了使列居中,您可以删除[l]

\begin{tabular}{@{}ccc@{}}
\toprule
\makecell{Original \\ Symbol} &
  \makecell{Mapped Symbol\\ with different\\ Real /Imaginary Axis} &
  \makecell{Mapped Symbol\\ with different\\ Real and Imaginary axis}\\
\midrule
$a$ & \makecell{Equal real parts ($c$ or $f$)\\Equal imaginary parts ($f$ or $e$)} &
  \makecell{$c$ or $e$\\ $d$ or $f$}\\
\addlinespace
$b$ & \makecell{Equal real parts ($d$ or $e$)\\Equal imaginary parts ($d$ or $c$)} &
  \makecell{$d$ or $f$ \\$c$ or $e$} \\
\bottomrule
\end{tabular}

在此处输入图片描述

最后,如果您希望表格填充文本宽度,请使用tabular*

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ccc@{}}
\toprule
\makecell{Original \\ Symbol} &
  \makecell{Mapped Symbol\\ with different\\ Real /Imaginary Axis} &
  \makecell{Mapped Symbol\\ with different\\ Real and Imaginary axis}\\
\midrule
$a$ & \makecell{Equal real parts ($c$ or $f$)\\Equal imaginary parts ($f$ or $e$)} &
  \makecell{$c$ or $e$\\ $d$ or $f$}\\
\addlinespace
$b$ & \makecell{Equal real parts ($d$ or $e$)\\Equal imaginary parts ($d$ or $c$)} &
  \makecell{$d$ or $f$ \\$c$ or $e$} \\
\bottomrule
\end{tabular*}

在此处输入图片描述

答案2

egreg 的答案解决了由于 而导致的扩展问题\resizebox

对齐问题是由于您l在所有表格中都使用了 参数。此外,当您使用嵌套表格时,很难看清发生了什么。下面是我第一个版本,其中我已将所有参数替换lc以使表格居中对齐。

然后我还有第二种选择,使用p{width}居中的版本。这是使用array包定义的。为了使ab符号垂直居中,我使用了multirow包。

\documentclass[12pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{graphicx}
\usepackage[left=1.50in, right=1.00in, top=1.25in, bottom=1.00in]{geometry}
\usepackage{booktabs}
%\usepackage{tabularx}
\usepackage{lipsum}
%%%
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{multirow}
%%%%%%%%%%%%%%%%%%
\begin{document}
\lipsum[1]
\begin{table}[!htbp]
  \caption{Table showing mapping  of sequences }
  \label{Table_CE1}
  \centering
  \begin{tabular}{@{}ccc@{}}
    \toprule
    \begin{tabular}[c]{@{}c@{}}{Original}\\   {Symbol}\end{tabular} & \begin{tabular}[c]{@{}c@{}}{Mapped Symbol}\\ {with different}\\ Real /Imaginary Axis\end{tabular} & \begin{tabular}[c]{@{}c@{}}{Mapped Symbol}\\ {with different}\\ Real and Imaginary axis\end{tabular}\\ \midrule
    a & \begin{tabular}[c]{@{}c@{}} Equal real parts (c or f)\\Equal imaginary parts (f or e )\end{tabular} & \begin{tabular}[c]{@{}c@{}} c or e\\ d or f \end{tabular}\\\\
    b & \begin{tabular}[c]{@{}c@{}} Equal real parts (d or e)\\Equal imaginary parts (d or c )\end{tabular} & \begin{tabular}[c]{@{}c@{}} d or f \\c or e  \end{tabular}\\
    \bottomrule  
  \end{tabular}
\end{table}

\begin{table}[!htbp]
  \caption{Alternative table showing mapping  of sequences }
  \label{Table_CE2}
  \centering
  \begin{tabular}{@{}P{20mm}P{56mm}P{55mm}@{}}
    \toprule
    Original Symbol & 
    Mapped Symbol with different Real /Imaginary Axis &
    Mapped Symbol with different Real and Imaginary axis \\
    \midrule
    \multirow{2}{*}{a} & Equal real parts (c or f) & c or e \\
    & Equal imaginary parts (f or e ) & d or f \\[5mm]
    \multirow{2}{*}{b} & Equal real parts (d or e) &  d or f \\
    & Equal imaginary parts (d or c ) & c or e \\
    \bottomrule  
  \end{tabular}
\end{table}
\lipsum[2]
\end{document}

在此处输入图片描述

答案3

另一种方法是使用tabularx表格环境(有了它,表格可以跨越文本宽度,从而利用所有可用的水平空间),multirow用于第一列中的单元格。makecell格式化第一列标题:

\documentclass[12pt,a4paper]{report}
\usepackage[left=1.50in, right=1.00in, 
            top=1.25in, bottom=1.00in]{geometry}
\usepackage[latin1]{inputenc}
\usepackage{booktabs, makecell, multirow, tabularx}
    \newcolumntype{C}{>{\centering\arraybackslash}X}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
    \begin{table}[htbp]
\caption{Table showing mapping  of sequences }
\label{Table_CE1}
    \centering
\begin{tabularx}{\linewidth}{cCC}%@{}
    \toprule
\makecell[t]{Original \\ Symbol}  
    &   Mapped Symbol with different Real /Imaginary Axis  
        &   Mapped Symbol  with different  Real and Imaginary axis    \\
    \midrule
\multirow{2}*{$a$}
    &   Equal real parts ($c$ or $f$)
        &   $c$ or $e$                      \\
    &   Equal imaginary parts ($f$ or $e$)
        &   $d$ or $f$                      \\
    \addlinespace
\multirow{2}*{$b$} 
    &   Equal real parts ($d$ or $e$)
        &   $d$ or $f$                      \\
    &   Equal imaginary parts ($d$ or $c$)  
        &   $c$ or $e$                      \\
    \bottomrule
\end{tabularx}
    \end{table}
\lipsum[2]
\end{document}

在此处输入图片描述

相关内容