我想用tabular
括号括起一个环境,放在enumerate
环境内部,然后顶部对齐。
在以下示例中:
\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
\(\left.\begin{tabular}{l}
First line\\
Second line\\
Third line
\end{tabular}\right\}\)
Text
\end{enumerate}
\end{document}
我得到了一切居中, 并不是顶部对齐:
如果我要求tabular
在顶部对齐,那么内联数学仍然不是,所以会发生以下情况:
\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
\(\left.\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}\right\}\)
Text
\end{enumerate}
\end{document}
有什么方法可以告诉内联数学也与顶部对齐?
答案1
我会定义一个新的环境并使用adjustbox
它。原理与 Heiko 的回答相同。
\documentclass[a4paper]{article}
\usepackage{adjustbox,varwidth,xparse}
\NewDocumentEnvironment{bracedrows}{m}
{\begin{adjustbox}{valign=t}%
$\kern-\nulldelimiterspace\left.
\begin{tabular}{@{}l@{}}}
{\end{tabular}\right\rbrace
\begin{varwidth}{.5\linewidth}#1\end{varwidth}$%
\end{adjustbox}}
\begin{document}
\begin{enumerate}
\item \begin{bracedrows}{Text}
First line\\
Second line\\
Third line
\end{bracedrows}
\item \begin{bracedrows}{Text in \\ two lines}
One\\
Two\\
Three
\end{bracedrows}
\end{enumerate}
\end{document}
确保varwidth
您的侧面文字仅占用必要的宽度。
答案2
\raisebox
就可以了。 的内容高度\raisebox
为\height
。tabular
环境将具有因子的支柱放在行中。由于表格的第一行仅包含普通文本,因此支柱很可能更大(并且可能大于花括号的延伸)。然后可以按以下方式计算\arraystretch
的参数:\raisbox
\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
\raisebox{%
\dimexpr
\arraystretch\dimexpr.7\baselineskip\relax
-\height
\relax
}{%
\(\left.\begin{tabular}{l}
First line\\
Second line\\
Third line
\end{tabular}\right\}\)
\parbox{0.5\linewidth}{Text}%
}%
\end{enumerate}
\end{document}
这个神奇的数字0.7
来自于支柱的定义latex.ltx
:
\setbox\strutbox\hbox{%
\vrule\@height.7\baselineskip
\@depth.3\baselineskip
\@width\z@
}%
Atabular
添加这些支柱,并乘以\arraystretch
以获得更均匀的线间距。
因此,源文件可以在没有魔法数字的情况下简化为:
\documentclass[a4paper]{article}
\begin{document}
\begin{enumerate}
\item
\raisebox{%
\dimexpr
\arraystretch\ht\strutbox
-\height
\relax
}{%
\(\left.\begin{tabular}{l}
First line\\
Second line\\
Third line
\end{tabular}\right\}\)
\parbox{0.5\linewidth}{Text}%
}%
\end{enumerate}
\end{document}
这\arraystretch\ht\strutbox
是第一行的高度和\height
的实际高度tabular
。
答案3
\documentclass[a4paper]{article}
\usepackage{multirow,bigdelim}
\begin{document}
\begin{enumerate}
\item
\begin{tabular}[t]{ll}
First line & \rdelim{\}}{3}{2.5cm}[Text]\\
Second line\\
Third line
\end{tabular}
\item foo
\end{enumerate}
\end{document}
答案4
尝试使用 TikZ
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{enumerate}
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}
\large
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}
\Large
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}
\LARGE
\item
\begin{tikzpicture}[baseline=(X.base)]
\node[inner sep=0pt] (X) {
\begin{tabular}[t]{l}
First line\\
Second line\\
Third line
\end{tabular}
};
\draw[decorate,decoration=brace] (X.north east) -- node[right=0.3em] {Text} (X.south east);
\end{tikzpicture}
\end{enumerate}
\end{document}