![너비 100% 및 수직/가로 정렬이 적용된 테이블](https://rvso.com/image/266422/%EB%84%88%EB%B9%84%20100%25%20%EB%B0%8F%20%EC%88%98%EC%A7%81%2F%EA%B0%80%EB%A1%9C%20%EC%A0%95%EB%A0%AC%EC%9D%B4%20%EC%A0%81%EC%9A%A9%EB%90%9C%20%ED%85%8C%EC%9D%B4%EB%B8%94.png)
LaTeX에서 다음 표를 그리고 싶습니다. 첫 번째 열의 텍스트는 왼쪽 정렬되어야 합니다. 다른 모든 셀의 텍스트는 중앙에 위치해야 합니다. 첫 번째 문제는 첫 번째 행의 D에서 발생합니다. \centering
앞에 a를 쓰면 D
LaTeX 오류가 발생합니다. 두 번째 문제는 모든 셀의 텍스트를 수직으로 정렬하고 싶지만 방법을 모른다는 것입니다. 해결책을 찾았지만 첫 번째 열의 너비가 지정되면 작동하지 않습니다.
\documentclass{article}
\usepackage{blindtext}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|p{4cm}|X|X|X|X|}
\hline
& \centering A & \centering B & \centering C & D\\
\hline
\blindtext & 123 & 123 & 123 & 123\\
\hline
\end{tabularx}
\end{document}
답변1
가로 및 세로 중앙에 있는 텍스트의 경우 X 열 정의를 다시 정의합니다.
\documentclass{article}
\usepackage{ragged2e}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{>{\Centering}m{#1}}
\newcommand\TEXT{%
I want to draw the following table in Latex. In the first column the text should be left aligned. The text in all other cells should be centered.}% only for demo
\begin{document}
\begin{tabularx}{\textwidth}{|m{4cm}*4{|X}|}\hline
& A & B & C & D \\\hline
\TEXT\TEXT & 123 & 123 & 123 & \TEXT\\\hline
\end{tabularx}
\end{document}
답변2
표준 TeX 방법으로 정렬을 수행할 수 있지만 LaTeX ragged2e
패키지를 사용하면 더 좋습니다.
\documentclass{article}
\usepackage{blindtext}
\usepackage{tabularx}
\usepackage{ragged2e}
\begin{document}
\begin{tabularx}{\textwidth}{|>{\RaggedRight}p{4cm}*{5}{|>{\Centering}X}|}
\hline
& A & B & C & D\\
\hline
\blindtext & 123 & 123 & 123 & 123\\
\hline
\end{tabularx}
\end{document}
열 X
은 기본적으로 열입니다 p{...}
. 따라서 \RaggedRight
각 셀의 시작 부분 과 같은 명령을 사용할 수 있습니다 . 각 셀에 대해 자동으로 수행하려면 >{..}
해당 행의 각 셀 시작 부분에 중괄호 내용을 삽입하는 을 사용하면 됩니다.
마지막 5개 셀의 반복을 피하기 위해 구문을 삽입했습니다 *{5}{...}
.