修改 booktabs 表的全局大小

修改 booktabs 表的全局大小

这是我想制作的表格:

\documentclass{book}
\usepackage{tabularx, booktabs}
\usepackage{lipsum}

\begin{document}
\begin{table}
\centering


\begin{tabularx}{\textwidth}{lll}

 \toprule
Conditions & Items test corrects & Items test incorrects \\
 \midrule
 Non-adjacents & Fa\textunderscore Sol\textunderscore Ré\textunderscore (O\textunderscore P\textunderscore Q\textunderscore ) & *Do\#\textunderscore Sol\#\textunderscore Si (S\textunderscore R\textunderscore T) \\
 & Sol\#\textunderscore Do\#\textunderscore Si\textunderscore  (R\textunderscore S\textunderscore T) & *Ré\textunderscore Sol\textunderscore Fa (Q\textunderscore P\textunderscore O) \\
 & \textunderscore Do\textunderscore Fa\#\textunderscore Ré\# (\textunderscore u\textunderscore v\textunderscore w) & *La\textunderscore Mi\textunderscore La\# (\textunderscore y\textunderscore x\textunderscore z) \\
 & \textunderscore Mi\textunderscore La\textunderscore La\# (\textunderscore x\textunderscore y\textunderscore z) & *Ré\#\textunderscore Fa\#\textunderscore Do (\textunderscore w\textunderscore v\textunderscore u) \\
Adjacents &  Ré.Ré\#.Fa.Do.Sol.Fa\# (QwOuPv) & *Si.La.Sol\#.La\#.Do\#.Mi (TyRzSx) \\ 
 & Ré.La\#.Fa.Mi.Sol.La (QzOxPy) & *Si.Fa\#.Sol\#.Ré\#.Do\#.Do (TvRwSu) \\ 
 & Si.Ré\#.Sol\#.Do.Do\#.Fa\# (TwRuSv) & *Ré.La.Fa.La\#.Sol.Mi (QyOzPx) \\ 
 & Si.La\#.Sol\#.Mi.Do\#.La (TzRxSy) & *Ré.Fa\#.Fa.Ré\#.Sol.Do QvOwPu) \\ 
 \bottomrule 

\end{tabularx}

\end{table}

\lipsum

\end{document}

结果如下:

在此处输入图片描述

我尝试减小表格的宽度,\footnotesize但表格中的文本仍然稍微超出右边距:

在此处输入图片描述

问题:

有没有办法强制所有表格与带有书本标签的文本保持对齐?

答案1

tabularx依我看,你不想要。

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{lipsum}

\newcommand{\sh}{$\sharp$}

\begin{document}
\lipsum[2]

\begin{table}[htp]
\centering
\footnotesize

\begin{tabular}{lll}
 \toprule
Conditions & Items test corrects & Items test incorrects \\
 \midrule
Non-adjacents & Fa\_Sol\_Ré\_(O\_P\_Q\_) & *Do\sh\_Sol\sh\_Si (S\_R\_T) \\
 & Sol\sh\_Do\sh\_Si\_ (R\_S\_T) & *Ré\_Sol\_Fa (Q\_P\_O) \\
 & \_Do\_Fa\sh\_Ré\sh (\_u\_v\_w) & *La\_Mi\_La\sh (\_y\_x\_z) \\
 & \_Mi\_La\_La\sh (\_x\_y\_z) & *Ré\sh\_Fa\sh\_Do (\_w\_v\_u) \\
Adjacents &  Ré.Ré\sh.Fa.Do.Sol.Fa\sh (QwOuPv) & *Si.La.Sol\sh.La\sh.Do\sh.Mi (TyRzSx) \\
 & Ré.La\sh.Fa.Mi.Sol.La (QzOxPy) & *Si.Fa\sh.Sol\sh.Ré\sh.Do\sh.Do (TvRwSu) \\
 & Si.Ré\sh.Sol\sh.Do.Do\sh.Fa\sh (TwRuSv) & *Ré.La.Fa.La\sh.Sol.Mi (QyOzPx) \\
 & Si.La\sh.Sol\sh.Mi.Do\sh.La (TzRxSy) & *Ré.Fa\sh.Fa.Ré\sh.Sol.Do QvOwPu) \\
 \bottomrule
\end{tabular}

\end{table}

\lipsum[3]

\end{document}

在此处输入图片描述

如果我尝试使用 进行相同的操作\begin{tabularx}{lXX},我会发现一行被拆分成两行(带有错误的连字符,除非我禁用表格的连字符)。更好的结果是使用以下规范@{}lXX@{}

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,booktabs}
\usepackage{lipsum}

\newcommand{\sh}{$\sharp$}

\begin{document}
\lipsum[2]

\begin{table}[htp]
\centering
\footnotesize
\hyphenpenalty=10000
\begin{tabularx}{\textwidth}{@{}lXX@{}}
 \toprule
Conditions & Items test corrects & Items test incorrects \\
 \midrule
Non-adjacents & Fa\_Sol\_Ré\_(O\_P\_Q\_) & *Do\sh\_Sol\sh\_Si (S\_R\_T) \\
 & Sol\sh\_Do\sh\_Si\_ (R\_S\_T) & *Ré\_Sol\_Fa (Q\_P\_O) \\
 & \_Do\_Fa\sh\_Ré\sh (\_u\_v\_w) & *La\_Mi\_La\sh (\_y\_x\_z) \\
 & \_Mi\_La\_La\sh (\_x\_y\_z) & *Ré\sh\_Fa\sh\_Do (\_w\_v\_u) \\
Adjacents &  Ré.Ré\sh.Fa.Do.Sol.Fa\sh (QwOuPv) & *Si.La.Sol\sh.La\sh.Do\sh.Mi (TyRzSx) \\
 & Ré.La\sh.Fa.Mi.Sol.La (QzOxPy) & *Si.Fa\sh.Sol\sh.Ré\sh.Do\sh.Do (TvRwSu) \\
 & Si.Ré\sh.Sol\sh.Do.Do\sh.Fa\sh (TwRuSv) & *Ré.La.Fa.La\sh.Sol.Mi (QyOzPx) \\
 & Si.La\sh.Sol\sh.Mi.Do\sh.La (TzRxSy) & *Ré.Fa\sh.Fa.Ré\sh.Sol.Do QvOwPu) \\
 \bottomrule
\end{tabularx}

\end{table}

\lipsum[3]

\end{document}

但结果会随着文本宽度的变化而变化。

在此处输入图片描述

注意tabularx 需求至少有一X列才能工作。

还请注意,这\#不是升号的正确符号。我将其定义\sh$\sharp$\sharp默认情况下,该命令仅在数学模式下可用)。

答案2

lcr)列不会在内容达到某个限制时中断。由于您使用tabularx的总宽度为,\textwidth因此最好使用

\begin{tabularx}{\textwidth}{lXX}     %%<-- note 2 X columns.

此处的X列为您提供宽度相等的列,内容到达末尾时会中断。

\documentclass{book}
\usepackage{tabularx, booktabs}
\usepackage{lipsum}

\begin{document}
\begin{table}
\centering


\begin{tabularx}{\textwidth}{lXX}

 \toprule
Conditions & Items test corrects & Items test incorrects \\
 \midrule
 Non-adjacents & Fa\textunderscore Sol\textunderscore Ré\textunderscore (O\textunderscore P\textunderscore Q\textunderscore ) & *Do\#\textunderscore Sol\#\textunderscore Si (S\textunderscore R\textunderscore T) \\
 & Sol\#\textunderscore Do\#\textunderscore Si\textunderscore  (R\textunderscore S\textunderscore T) & *Ré\textunderscore Sol\textunderscore Fa (Q\textunderscore P\textunderscore O) \\
 & \textunderscore Do\textunderscore Fa\#\textunderscore Ré\# (\textunderscore u\textunderscore v\textunderscore w) & *La\textunderscore Mi\textunderscore La\# (\textunderscore y\textunderscore x\textunderscore z) \\
 & \textunderscore Mi\textunderscore La\textunderscore La\# (\textunderscore x\textunderscore y\textunderscore z) & *Ré\#\textunderscore Fa\#\textunderscore Do (\textunderscore w\textunderscore v\textunderscore u) \\
Adjacents &  Ré.Ré\#.Fa.Do.Sol.Fa\# (QwOuPv) & *Si.La.Sol\#.La\#.Do\#.Mi (TyRzSx) \\
 & Ré.La\#.Fa.Mi.Sol.La (QzOxPy) & *Si.Fa\#.Sol\#.Ré\#.Do\#.Do (TvRwSu) \\
 & Si.Ré\#.Sol\#.Do.Do\#.Fa\# (TwRuSv) & *Ré.La.Fa.La\#.Sol.Mi (QyOzPx) \\
 & Si.La\#.Sol\#.Mi.Do\#.La (TzRxSy) & *Ré.Fa\#.Fa.Ré\#.Sol.Do QvOwPu) \\
 \bottomrule

\end{tabularx}

\end{table}

\lipsum

\end{document}

在此处输入图片描述

相关内容