영리한 표 행 서식 솔루션

영리한 표 행 서식 솔루션

얼마 전 @robintw가 실용적인 질문을 했습니다. 표의 첫 번째 행을 모두 굵게 표시

배열 패키지를 사용하여 헤더 행 열에 형식 지정 코드를 교묘하게 삽입합니다.

영리한 표 행 서식 솔루션

\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}} % Always set currentrowstyle to \relax in case no \rowstyle is used
\newcolumntype{^}{>{\currentrowstyle}} % set \currentrowstyle to \bfseries or whatever (>{\bfseries}c)
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}% set global definition for \currentrowstyle
  #1\ignorespaces
}

문제가 있는 코드

다중 열 및 다중 행 지원을 보고 싶습니다. 나는 다음을 기반으로 시도했습니다.https://tex.stackexchange.com/a/4816/13552, 작동하지 않습니다.

\documentclass{article}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
\begin{tabular}{$l^c^c^r}
\rowstyle{\bfseries}
%\multicolumn{2}{^l}{span2} & \multicolumn{2}{^r}{span2} \\ % Uncomment this to see problem
col1 & col2 & col3 & col4 \\
dat1 & dat2 & dat3 & dat4 \\
\end{tabular}
\end{document}

답변1

$>문제는 테이블 형식의 첫 번째 행에서 열 유형이 전혀 사용되지 않는다는 사실과 관련이 있습니다 .

다음을 사용하여 이 문제를 해결할 수 있습니다.

\multicolumn{2}{$l}{}

첫 번째 스팬 열 세트의 경우. 그러나 문제는 일이 잘못된 순서로 진행된다는 것입니다. \rowstyle{\bfseries}이제 첫 번째 셀이 시작되기 전입니다. 이 문제를 해결하려면 첫 번째 셀의 사양에 이를 포함하면 됩니다.

\multicolumn{2}{$l}{\rowstyle{\bfseries}span2}

생산하는

확장된 행 스타일

내가 올바르게 이해했다면 이는 예상된 결과입니다.

완전한 코드

\documentclass{article}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
  \begin{tabular}{$l^c^c^r}
    \multicolumn{2}{$l}{\rowstyle{\bfseries}span2} & \multicolumn{2}{^r}{span2} \\ % Uncomment this to see problem
    col1 & col2 & col3 & col4 \\
    dat1 & dat2 & dat3 & dat4 \\
  \end{tabular}
\end{document}

관련 정보