
테이블의 나머지 부분과 정렬하는 방법을 잘 모르는 여러 열 요소가 있습니다.
코드:
\documentclass{article}
\begin{document}
\begin{tabular}{l|p{0.5\linewidth}}
Item 1 & This part contains multiple lines and I want the multicolumn on the bottom to align with it. \\
Item 2 & Something else here. \\
\hline
\multicolumn{2}{p{0.6\linewidth}}{I want this text to be aligned with the rest of the columns.}
\end{tabular}
\end{document}
아래쪽 부분을 다른 열의 빨간색 선과 정렬하고 싶습니다. 이를 달성하기 위한 접근 방식은 무엇입니까?
답변1
이 코드를 사용해 보세요. 솔루션은 두 열의 너비를 미리 정의한 다음 이전 두 너비의 합에 표 형식 열 간격의 2배를 더한 값으로 마지막 행의 너비를 계산합니다. calc
계산을 명시적으로 만들기 위해 패키지를 추가했습니다 .
\documentclass{article}
\usepackage{calc}
\begin{document}
\begin{tabular}{l|p{0.5\linewidth}}
Item 1 & This part contains multiple lines and I want the multicolumn on the bottom to align with it. \\
Item 2 & Something else here. \\
\hline
\multicolumn{2}{p{0.6\linewidth}}{I want this text to be aligned with the rest of the columns.}
\end{tabular}
\vspace{3\baselineskip}
\newlength{\colwidthi}
\settowidth{\colwidthi}{Item 1}
\newlength{\colwidthii}
\setlength{\colwidthii}{0.5\linewidth}
\newlength{\colwidthiii}
\setlength{\colwidthiii}{\colwidthi+\colwidthii+ 2\tabcolsep}
\begin{tabular}{p{\colwidthi}|p{\colwidthii}}
Item 1 &This part contains multiple lines and I want the multicolumn on the bottom to align with it. \\
Item 2 & Something else here. \\
\hline
\multicolumn{2}{p{\colwidthiii}}{I want this text to be aligned with the rest of the columns.} \\
\end{tabular}%
\end{document}
답변2
새로운 LaTeX3 패키지tabularray
hspan=minimal
열 너비에서 범위 너비를 계산하는 옵션을 제공합니다 .
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{colspec={l|p{0.5\linewidth}},hspan=minimal}
Item 1 & This part contains multiple lines and I want the multicolumn on the bottom to align with it. \\
Item 2 & Something else here. \\
\hline
\SetCell[c=2]{l} I want this text to be aligned with the rest oofff the columns. & \\
\end{tblr}
\end{document}