
표를 만들었는데 캡션(또는 그 뒤에 추가하는 모든 텍스트)이 표 중앙에 있습니다. 마치 표가 두 번째 행 다음에 끝난 것처럼 보입니다. 비슷한 질문을 찾을 수 없어서 스스로에게 물어보기로 했습니다.
캡션이나 캡션 앞/뒤의 텍스트가 없으면 표는 내가 원하는 모습과 거의 비슷해 보입니다.
\documentclass{report}
\usepackage{multirow}
\begin{document}
This is some text and here is a reference to Table \ref{table:mytable}.
\begin{table} [h]
\centering
\begin{tabular} {c c c} \\
\textbf{Column A} & \textbf{Column B} & \textbf{Column C} \\
\hline
\multirow{3}{*}{\textbf{Test1}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}} \\
\multirow{6}{*}{\textbf{Test2}}
& \multicolumn{2}{c}{ \multirow{6}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}} \\
\multirow{9}{*}{\textbf{Test3}}
& \multirow{9}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}
& \multirow{9}{*}{\shortstack[l]{line1 \\ line2 \\ line3}} \\
\multirow{12}{*}{\textbf{Test4}}
& \multirow{12}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}
& \multirow{12}{*}{\shortstack[l]{line1 \\ line2 \\ line3}} \\
\end{tabular}
\label{table:mytable}
\caption{This is the caption.}
\end{table}
\end{document}
참고로, 참조도 어떤 이유로 제대로 작동하지 않습니다. 나는 그 문장이 말하고 싶었다.
[...] 여기에 표 1에 대한 참조가 있습니다.
대신에 그것은 단지 말한다
[...] 여기에 Table 에 대한 참조가 있습니다.
\ref
나는 다른 테이블과 함께 사용할 수 있었지만 이 테이블은 사용할 수 없습니다.
답변1
\multirow{<nrows>}{<width>}{<text>}
<nrows>
width 행 에 걸쳐 텍스트를 (수직으로) 펼칩니다 <width>
. <width>
로 주어지면 의 *
자연스러운 너비를 사용합니다 <text>
. 예를 들어 를 사용한다는 것은 \multirow{12}{*}{<...>}
해당 특정 셀을 12개 행에 걸쳐 펼치려는 것을 의미합니다. 각 TestX
행을 3개 행에만 분산시키려고 하기 때문에 분명히 잘못된 것입니다 .
다음은 약간 다른 구현입니다.multirow
여기)를 사용하여makecell
:
\documentclass{report}
\usepackage{makecell}
\begin{document}
This is some text and here is a reference to Table~\ref{table:mytable}.
\begin{table} [h]
\centering
\begin{tabular} {c c c}
\textbf{Column A} & \textbf{Column B} & \textbf{Column C} \\
\hline
\textbf{Test1}
& \makecell{line1 \\ line2 \\ line3}
& \makecell{line1 \\ line2 \\ line3} \\
\textbf{Test2}
& \multicolumn{2}{c}{\makecell{line1 \\ line2 \\ line3}} \\
\textbf{Test3}
& \makecell{line1 \\ line2 \\ line3}
& \makecell{line1 \\ line2 \\ line3} \\
\textbf{Test4}
& \makecell{line1 \\ line2 \\ line3}
& \makecell{line1 \\ line2 \\ line3}
\end{tabular}
\caption{This is the caption.}
\label{table:mytable}
\end{table}
\end{document}
어떻게 \label
오는지 참고하세요~ 후에 \caption
올바른 erence를 달성하기 위해 \ref
. 보다캡션 뒤에 환경 레이블이 표시되어야 하는 이유는 무엇입니까?.
답변2
질문에 대한 댓글을 쓰면서 당신은 어떻게 오해했는지여러 줄행 범위를 계산하지만 쉽게 수정됩니다. 모든 장소 3개만 추가하세요(즉6, 9, 12 대신).
잘못 배치된 캡션을 수정하려면 원본 코드를 사용하려는 경우 -row 뒤에 추가 공간을 추가하여 multirow
확장된 행에 충분한 공간을 만들어야 합니다. 세 행에 걸쳐 있기 때문에 두 행을 추가하거나( &&\\
) 명령에서 비슷한 양의 추가 높이를 추가할 수 있습니다 end-of-row
( . 공간이 세 행과 동일하도록 \\[<height>]
두 개의 를 추가했습니다 .\normalbaselineskip
실제로 추가 패키지를 전혀 사용하지 않고도 이 테이블을 조판할 수 있습니다. a를 정의 \parbox
하고 그 안에 세 줄을 배치합니다. \parbox
올바른 간격을 가지 려면 높이와 너비를 결정해야 합니다 . 문서에 적합한 간격을 갖도록 높이 및 너비 매개변수를 변경할 수 있습니다. 이를 피하고 싶다면 를 사용하세요 makecell
. \pb
타이핑을 줄이기 위해 단축키를 정의했습니다 .
라벨을 보관하는 가장 안전한 장소는 다음과 같습니다.내부에캡션 명령. 그러면 실패하지 않을 것입니다.
테이블\parbox
\documentclass{report}
%\usepackage{multirow}
\newcommand{\pb}[1]{\parbox[c][40pt][c]{0.2\linewidth}{\centering #1}}
\begin{document}
\begin{table}
\caption{This is the caption.\label{table:mytable}}
\centering
\begin{tabular} {@{}c c c@{}} \\
\bfseries Column A & \bfseries Column B & \bfseries Column C \\\hline
\bfseries Test1 & \pb{line1 \\ line2 \\ line3} & \pb{line1 \\ line2 \\ line3} \\
\bfseries Test2 & \multicolumn{2}{c}{\pb{line1 \\ line2 \\ line3}} \\
\bfseries Test3 & \pb{line1 \\ line2 \\ line3} & \pb{line1 \\ line2 \\ line3}\\
\bfseries Test4 & \pb{line1 \\ line2 \\ line3} & \pb{line1 \\ line2 \\ line3}\\\hline
\end{tabular}
\end{table}
\end{document}
테이블\multirow
\documentclass{report}
\usepackage{multirow}
\begin{document}
This is some text and here is a reference to Table \ref{table:mytable}. As you see, the table is a float, and since you have available space, it is place at top of the page. Do not mess around with placing floats before you have finished all creative writing. Everting you do, will be invalid when you add more text.
\begin{table}
\centering
\begin{tabular} {c c c} \\
\textbf{Column A} & \textbf{Column B} & \textbf{Column C} \\
\hline
\multirow{3}{*}{\textbf{Test1}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}} \\[2\normalbaselineskip] % Add more space
\multirow{3}{*}{\textbf{Test2}}
& \multicolumn{2}{c}{ \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}} \\[2\normalbaselineskip] \multirow{3}{*}{\textbf{Test3}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}} \\[2\normalbaselineskip]
\multirow{3}{*}{\textbf{Test4}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}}
& \multirow{3}{*}{\shortstack[l]{line1 \\ line2 \\ line3}} \\[2\normalbaselineskip]
\end{tabular}
\caption{This is the caption.\label{table:mytable}}
\end{table}
\end{document}
답변3
역시 를 기반으로 하는 변형 코드는 - 및 와 makecell
결합되어 규칙 주위에 패딩을 추가합니다. 세 줄의 그룹을 구분하기 위해 세로 간격을 추가했습니다. 또한 에 대한 참조가 작동하려면 캡션 뒤의 명령이 필요합니다.multirow
booktabs
\label
\documentclass{report}
\usepackage{multirow}
\usepackage{makecell, booktabs}
\renewcommand{\theadfont}{\normalsize\bfseries}
\begin{document}
This is some text and here is a reference to Table \ref{table:mytable}.
\begin{table} [h]
\centering
\begin{tabular} {c c c} \\
\textbf{Column A} & \textbf{Column B} & \textbf{Column C} \\
\midrule
\multirowthead{3}{Test1} & line1 & line1 \\
& line2 & line2 \\
& line3 & line 3\\
\addlinespace
\textbf{Test2} & \multicolumn{2}{c}{\makecell{line1 \\ line2 \\ line3}} \\
\addlinespace
\multirowthead{3}{Test 3} & line1 & line1 \\
& line2 & line2 \\
& line3 & line 3\\
\addlinespace
\multirowthead{3}{Test 4} & line1 & line1 \\
& line2 & line2 \\
& line3 & line 3\\
\bottomrule
\end{tabular}
\label{table:mytable}
\caption{This is the caption.}\label{table:mytable}
\end{table}
\end{document}