![跨多个“表格”块进行对齐](https://linux22.com/image/404926/%E8%B7%A8%E5%A4%9A%E4%B8%AA%E2%80%9C%E8%A1%A8%E6%A0%BC%E2%80%9D%E5%9D%97%E8%BF%9B%E8%A1%8C%E5%AF%B9%E9%BD%90.png)
因此,在下面的代码中,第一部分和第二部分的单元格将处于不同的水平高度。我该如何对齐它们?我希望它们都与第一部分的单元格处于同一水平。第二部分的左侧也应与右侧对齐。我该如何实现这一点?
\documentclass[a4paper,10pt]{article}
\begin{document}
\section{First Section}
\begin{tabular}{rl}
\textsc{September} 2014 --- \textsc{May} 2018 & Cell 1\\
& Cell 2\\
\end{tabular}
\section{Second Section}
\begin{tabular}{rl}
\textsc{May} 2014 --- \textsc{May} 2018 & Cell 3\\
& Cell 4\\
\textsc{May} 2006 --- \textsc{May} 2028 & Cell 5\\
& Cell 6\\
\end{tabular}
\end{document}
答案1
欢迎!您可以使用该eqparbox
包来同步宽度。
\documentclass[a4paper,10pt]{article}
\usepackage{eqparbox}
\begin{document}
\section{First Section}
\begin{tabular}{rl}
\eqmakebox[A][r]{\textsc{September} 2014 --- \textsc{May} 2018} & Cell 1\\
& Cell 2\\
\end{tabular}
\section{Second Section}
\begin{tabular}{rl}
\eqmakebox[A][r]{\textsc{May} 2014 --- \textsc{May} 2018} & Cell 3\\
& Cell 4\\
\eqmakebox[A][r]{\textsc{May} 2006 --- \textsc{May} 2028} & Cell 5\\
& Cell 6\\
\end{tabular}
\end{document}
您还可以引入一种新的列类型(Q
此处称为),使宽度相等。然后您只需使用此类型即可。
\documentclass[a4paper,10pt]{article}
\usepackage{eqparbox}
\usepackage{array}
\newbox\eqtabbox
\newcolumntype{Q}{>{\setbox\eqtabbox=\hbox\bgroup}r<{\egroup
\eqmakebox[Q][r]{\copy\eqtabbox}}}
\begin{document}
\section{First Section}
\begin{tabular}{Ql}
\textsc{September} 2014 --- \textsc{May} 2018 & Cell 1\\
& Cell 2\\
\end{tabular}
\section{Second Section}
\begin{tabular}{Ql}
\textsc{May} 2014 --- \textsc{May} 2018 & Cell 3\\
& Cell 4\\
\textsc{May} 2006 --- \textsc{May} 2028 & Cell 5\\
& Cell 6\\
\end{tabular}
\end{document}
您还可以让其Q
采用表示对齐的参数。
\documentclass[a4paper,10pt]{article}
\usepackage{eqparbox}
\usepackage{array}
\newbox\eqtabbox
\newcolumntype{Q}[1]{>{\setbox\eqtabbox=\hbox\bgroup}#1<{\egroup
\eqmakebox[Q][#1]{\copy\eqtabbox}}}
\begin{document}
\section{First Section}
\begin{tabular}{Q{r}l}
\textsc{September} 2014 --- \textsc{May} 2018 & Cell 1\\
& Cell 2\\
\end{tabular}
\section{Second Section}
\begin{tabular}{Q{r}l}
\textsc{May} 2014 --- \textsc{May} 2018 & Cell 3\\
& Cell 4\\
\textsc{May} 2006 --- \textsc{May} 2028 & Cell 5\\
& Cell 6\\
\end{tabular}
\end{document}
或者两个参数,其中第一个参数是标识符,以防您有不同的列。
\documentclass[a4paper,10pt]{article}
\usepackage{eqparbox}
\usepackage{array}
\newbox\eqtabbox
\newcolumntype{Q}[2]{>{\setbox\eqtabbox=\hbox\bgroup}#2<{\egroup
\eqmakebox[#1][#2]{\copy\eqtabbox}}}
\begin{document}
\section{First Section}
\begin{tabular}{Q{A}{r}l}
\textsc{September} 2014 --- \textsc{May} 2018 & Cell 1\\
& Cell 2\\
\end{tabular}
\section{Second Section}
\begin{tabular}{Q{A}{r}l}
\textsc{May} 2014 --- \textsc{May} 2018 & Cell 3\\
& Cell 4\\
\textsc{May} 2006 --- \textsc{May} 2028 & Cell 5\\
& Cell 6\\
\end{tabular}
\end{document}