
LaTeX Table &&
을 &0&
. 따라서 공백은 문자 그대로의 NA 또는 여기에 해당하는 것이 아닙니다. 암호
\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{| l | l | l |}
AHB && \\ \hline
\end{tabular}
\end{table}
\end{document}
테이블 행을 다음으로 변경합니다.
AHB 1 && 1 \\ \hline
해석됐으면 좋겠다
AHB 1 &0& 1 \\ \hline
답변1
당신은 할 수 있습니다셀 내용을 수집그리고비어 있는지 테스트:
\documentclass{article}
\usepackage{collcell}
\newcommand{\emptytozero}[1]{% https://tex.stackexchange.com/q/53068/5764
\if\relax\detokenize{#1}\relax
0%
\else
#1%
\fi
}
\begin{document}
\begin{tabular}{ c | >{\collectcell\emptytozero}c<{\endcollectcell} }
& \\
& 1 \\
1 & \\
1 & 1
\end{tabular}
\end{document}
여러 열을 검사해야 하는 경우 새 열 유형을 정의할 수 있습니다(collcell
잔뜩array
.) \newcolumntype
:
\newcolumntype{C}{ >{\collectcell\emptytozero}c<{\endcollectcell} }
답변2
다음은 빈 표 형식 셀을 0으로 채우는 매우 간단한 버전입니다. 검사는 z
필요한 경우 0으로 채워야 하는 모든 열에 사용해야 하는 새로운 열 형식으로 수행됩니다.
\documentclass{article}
\usepackage{array}
\newcolumntype{z}{>{\zeroIfEmpty}l<{\endzero}}
\def\zeroIfEmpty#1\endzero{\setbox0=\hbox{#1}\ifdim\wd0=0pt 0\else#1\fi}
\begin{document}
\begin{tabular}{| z | z | z | l }
& & &\\
& & 1 &\\
& 1 & &\\
1 & & &\\
1 & 1 & 1 &\\
\end{tabular}
\end{document}
이는 몇 가지 더 복잡한 상황에서 중단될 가능성이 있는 매우 간단한 검사입니다. 예를 들어 표의 마지막 열에 사용되면 중단됩니다(예제에 표시된 것처럼 추가 빈 열로 수정될 수 있음). 따라서 아예 사용하지 않는 것이 더 나을 수도 있습니다. ;-)