테이블 형식x 셀을 중앙에 배치할 때 위치가 잘못되었습니다.

테이블 형식x 셀을 중앙에 배치할 때 위치가 잘못되었습니다.

다음과 같은 최소한의 LaTeX 문서가 있습니다.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
  \noindent
  \begin{tabularx}{\linewidth}{ X | X }
    \centering A & B \\ \hline
    1.0 & 2.0 \\
  \end{tabularx}
\end{document}

AB 1.0 2.0

테이블 헤더를 중앙에 배치하고 열을 왼쪽 정렬하고 싶습니다. 그러나 \centeringB 헤더에 다음과 같이 추가하면 다음과 같습니다.

\documentclass{article}
\usepackage{tabularx}
\begin{document}
  \noindent
  \begin{tabularx}{\linewidth}{ X | X }
    \centering A & \centering B \\ \hline
    1.0 & 2.0 \\
  \end{tabularx}
\end{document}

다음 오류가 발생합니다.

! Misplaced \noalign.
\hline ->\noalign
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.8   \end{tabularx}

! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate

l.8   \end{tabularx}

! Misplaced \noalign.
\hline ->\noalign
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.8   \end{tabularx}

! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate

l.8   \end{tabularx}

! Misplaced \noalign.
\hline ->\noalign
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.8   \end{tabularx}

! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate

l.8   \end{tabularx}

답변1

문서 2페이지에는 (또는 또는 ) 이후에 tabularx사용해야 한다고 나와 있습니다 . 다음과 같이 사용하세요:\arraybackslash\centering\raggedright\ragggedleft

\documentclass{article}
\usepackage{tabularx}
\begin{document}
  \noindent
  \begin{tabularx}{\linewidth}{ X | X }
    \centering\arraybackslash A & \centering\arraybackslash B \\ \hline
    1.0 & 2.0 \\
  \end{tabularx}
\end{document}

LaTeX의 텍스트 정렬 명령은 \\더 이상 "테이블의 새 줄"을 의미하지 않도록 재정의되었습니다. 이 \arraybackslash명령은 \let\\\tabularnewline다시 작동하도록 합니다.

또는 첫 번째 행 끝에서 \tabularnewline대신 사용할 수 있습니다 .\\

\documentclass{article}
\usepackage{tabularx}
\begin{document}
  \noindent
  \begin{tabularx}{\linewidth}{ X | X }
    \centering A & \centering B \tabularnewline \hline
    1.0 & 2.0 \\
  \end{tabularx}
\end{document}

답변2

\multicolumn{1}{c}{...}간단히 열 머리글에 a를 사용할 수 있습니다 . 또는 모든 인수 의 공통 형식을 정의할 수 있는 명령을 로드 makecell하고 사용합니다 (기본적으로 해당 내용은 가로 및 세로 모두 중앙에 위치함). 다음은 두 가지 방법의 예입니다.theadthead

\documentclass{article}
\usepackage{tabularx, makecell, xcolor}
\renewcommand{\theadfont}{\normalsize\bfseries\color{red}}

\begin{document}

  \noindent
  \begin{tabularx}{\linewidth}{ X | X }
    \multicolumn{1}{c}{A} & \multicolumn{1}{c}{B} \\ \hline
    1.0 & 2.0 \\
  \end{tabularx}
\vspace{4ex}

  \noindent
  \begin{tabularx}{\linewidth}{ X | X }
    \thead{A} & \thead{B} \\ \hline
    1.0 & 2.0 \\
  \end{tabularx}

\end{document} 

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

관련 정보