
Вот таблица, которую я пытаюсь составить:
\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
l
( c
и r
тоже) столбец не сломается, когда содержимое достигнет некоторого предела. Поскольку вы используете 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}