손으로 감싼 여러 줄 셀이 있는 테이블에서 셀의 수직 중심 맞추기

손으로 감싼 여러 줄 셀이 있는 테이블에서 셀의 수직 중심 맞추기

테이블 셀의 수직 센터링에 대한 수십 가지 답변에도 불구하고 저는 손으로 감싼 여러 줄 셀의 동일한 행에 있는 셀의 수직 센터링이라는 단순한 요구 사항에 대한 솔루션을 찾을 수 없었습니다(내 잘못).

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{array}
\begin{document}
\pagecolor{yellow!10}

\newcommand{\methoda}[1]{{\parbox[c]{\linewidth}{\centering#1}}}
\newcommand{\methodb}[3]{\begin{tabular}[c]{@{}c@{}}#1\\#2\\#3\end{tabular}}
\newcommand{\methodc}[1]{\begin{minipage}[m]{\linewidth}\centering#1\end{minipage}}
\newcommand{\methodd}[1]{{\begin{center}#1\end{center}}}
\newcommand{\methoddfix}[1]{{\setlength{\topsep}{0pt}\begin{center}#1\end{center}}}

\centering\begin{tabular}{>{\raggedright\arraybackslash}m{0.28\linewidth}>{\centering\arraybackslash}m{0.33\linewidth}}
\tabularnewline\hline
\centering Column 1 & Column 2\tabularnewline\hline
2 lines vertically centered & This cell contains more than one line of automatically wrapped text. \tabularnewline\hline
Fail of vertical centering & \methoda{Hand-wrapped\\ multiline\\ method A} \tabularnewline\hline
Vert. center. fail & \methodb{Hand-wrapped}{multiline}{method B} \tabularnewline\hline
Fail of vertical centering & \methodc{Hand-wrapped multiline\\ method C\\ too much padding} \tabularnewline\hline
Vert. center. OK & \methodd{Hand-wrapped multiline\\ method D\\ too much padding} \tabularnewline\hline
Success column 1, fail column 2 & \methoddfix{Hand-wrapped multiline\\ method Dfix\\ cannot remove\\ bottom padding} \tabularnewline\hline
Just a last row & Just a last row \tabularnewline\hline
\end{tabular}

\end{document}

여기에 이미지 설명을 입력하세요

내 실제 테이블은 다른 추가 고급 패키지를 longtable사용하고 multirow있으며 XeLaTeX로 컴파일되었습니다.tabularx

도움을 주셔서 미리 감사드립니다.

답변1

또는 makecell중첩된 tabulars와 p두 번째 열 유형:

여기에 이미지 설명을 입력하세요

\documentclass[12pt]{article}

\usepackage{array}
\usepackage{makecell}
\begin{document}

With a multicolumn around the automatically wrapped columns:
\centering\begin{tabular}{>{\raggedright\arraybackslash}m{0.28\linewidth}>{\centering\arraybackslash}p{0.33\linewidth}}
\hline
some automatically wrapped text & \makecell[cc]{Some \\ manually \\ linebroken \\ text \\ over multiple lines}\\ \hline
some automatically wrapped text & \begin{tabular}[c]{@{}c@{}}Some \\ manually \\ linebroken \\ text \\ over multiple lines\end{tabular}\\ \hline
some automatically wrapped text & \multicolumn{1}{>{\centering\arraybackslash}m{0.33\linewidth}}{some longer but also automatically wrapped text}\\ \hline
\end{tabular}


With a multicolumn around the manually wrapped columns:
\begin{tabular}{>{\raggedright\arraybackslash}m{0.28\linewidth}>{\centering\arraybackslash}m{0.33\linewidth}}
\hline
some automatically wrapped text & \multicolumn{1}{>{\centering\arraybackslash}p{0.33\linewidth}}{\makecell[cc]{Some \\ manually \\ linebroken \\ text \\ over multiple lines}}\\ \hline
some automatically wrapped text & \multicolumn{1}{>{\centering\arraybackslash}p{0.33\linewidth}}{\begin{tabular}[c]{@{}c@{}}Some \\ manually \\ linebroken \\ text \\ over multiple lines\end{tabular}}\\ \hline
some automatically wrapped text & some longer but also automatically wrapped text\\ \hline
\end{tabular}
\end{document}

업데이트:수동 및 자동 줄 바꿈을 결합하려면 초기 열 정의를 변경 \let\newline\\\arraybackslash\hspace{0pt}하여 \arraybackslash.

\documentclass[12pt]{article}

\usepackage{array}
\usepackage{makecell}
\begin{document}
\begin{tabular}{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{0.28\linewidth}>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{0.33\linewidth}}
\hline
some automatically wrapped text & some longer but also automatically wrapped text\\ \hline
some automatically wrapped text & some\newline automatically wrapped text with a\newline few \newline manual linebreaks\\ \hline
manual \newline linebreak & more text here\\
\hline
\end{tabular}
\end{document}

관련 정보