hline 和 ifthen 和 xtab

hline 和 ifthen 和 xtab

我正在尝试调试一堆程序生成的表的布局(有些longtable由于历史原因使用,有些使用tabular,有些使用xtab)。我真的很想\hline在这些表的每一行之后使用以查看发生了什么,然后\hline在不再需要它进行调试时抑制它。(我想对表格描述中由“|”产生的垂直线做同样的事情,但这似乎不太可能。)

我曾经ifthen定义过\hhline,即\hline如果设置了某个标志,则为,否则不为,但由于此处其他问题中描述的一些特殊情况,此方法失败。为了记录,我写道:

\newcommand{\lineflag}{true}
\newcommand{\hhline}{\ifthenelse{\equal{\lineflag}{true}}{\hline}{}}%

然后在我的桌子上,我有这样的东西

\begin{xtabular}{|p{\indexPageWidth}|p{\indexNameWidth}|}\hhline
}

一开始就在表格顶部画一条线,当然,LaTeX 反对。

正如我所说,我从阅读其他问答中了解到,这样做行不通,因为我已经这样做了。有没有办法得到相同的结果,即“当某个标志为真时显示所有表格单元格的轮廓形状,否则不显示”?

一个最小(ish)损坏的示例:

\documentclass[11pt,twoside]{article}
\usepackage{xtab}
\usepackage{ifthen}

\begin{document}

\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\
third item & fourth item
\end{xtabular}

\vspace{0.3in}
Now with hlines:

\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\\hline
third item & fourth item \\\hline
\end{xtabular}

\newcommand{\lineflag}{false}
\newcommand{\oline}{\ifthenelse{\equal{\lineflag}{true}}{\hline}{}}%
\vspace{0.3in}
Now with optional hlines; notice that the middle divider hangs down     because 
of the macro (even though it expands to nothing at all).
I also wish I could get an hline at the top as well, but I haven't figured that out either. 
Changing ``lineflag'' to ``true'' above will generate an error. 

\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\\oline%
third item & fourth item \\\oline%
\end{xtabular}

\end{document}

根据@DavidCarlisle的建议,我修改了该文件的最后三分之一

\newif\iflineflag
\lineflagtrue
% \lineflagfalse

\iflineflag\hline\fi

\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\\iflineflag\hline\fi
%
third item & fourth item \\\iflineflag\hline\fi
%

...一旦我摆脱了一些愚蠢的麻烦,它就完美地工作了。我宁愿只放一个命令行,\oline而不是\iflineflag\hline\fi,但我可以用这个。

答案1

你需要一个可扩展的测试,因为之前不能有不可扩展的标记\hline

在此处输入图片描述

\documentclass[11pt,twoside]{article}
\usepackage{xtab}
\newif\iflineflag
\newcommand{\oline}{\iflineflag\hline\fi}%
\begin{document}

\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\
third item & fourth item
\end{xtabular}

\vspace{0.3in}
Now with hlines:

\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\\hline
third item & fourth item \\\hline
\end{xtabular}



\vspace{0.3in}
Now with optional hlines; notice that the middle divider hangs down     because 
of the macro (even though it expands to nothing at all).
I also wish I could get an hline at the top as well, but I haven't figured that out either. 
Changing ``lineflag'' to ``true'' above will generate an error. 


\bigskip
TRUE

\lineflagtrue
\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\\oline%
third item & fourth item \\\oline%
\end{xtabular}


\bigskip
FALSE

\lineflagfalse
\begin{xtabular}
{p{1.0in}|p{2.0in}}
first item & second item\\\oline%
third item & fourth item \\\oline%
\end{xtabular}

\end{document}

相关内容