When I write truth tables I like a bit more space in the cells, so I assign new values to arraystretch
and tabcolsep
, like this …
\documentclass[12pt]{article}
\begin{document}
\renewcommand{\arraystretch}{1.5}
\renewcommand{\tabcolsep}{0.2cm}
\begin{tabular}{| c | c | c | c | c |}
\hline
$Q$ & $R$ & $Q \lor R$ \\ \hline \hline
T & T & T \\
T & F & T \\
F & T & T \\
F & F & F \\
\hline
\end{tabular}
\end{document}
… and all is well.
Eventually I made a new environment for truth tables:
\newenvironment{truthtabular}[1]{%
\renewcommand{\arraystretch}{1.5}
\renewcommand{\tabcolsep}{0.2cm}
\begin{tabular}{#1}{%
}
}{\end{tabular}}
The environment worked fine unless I wanted the hline at the top, in which case I would get the following errors:
Misplaced \noalign. \hline
You can't use `\hrule' here except with leaders. \hline
Missing number, treated as zero. \hline
Illegal unit of measure (pt inserted). \hline
Attempting to diagnose the problem, I removed the reassignments from the definition of the new environment, thus:
\newenvironment{truthtabular}[1]{%
%\renewcommand{\arraystretch}{1.5}
%\renewcommand{\tabcolsep}{0.2cm}
\begin{tabular}{#1}{%
}
}{\end{tabular}}
The compilations still fails, with the same errors, when beginning with an hline. Example of failure follows:
\documentclass[12pt]{article}
\begin{document}
\newenvironment{truthtabular}[1]{%
\begin{tabular}{#1}{%
}
}{\end{tabular}}
\begin{truthtabular}{| c | c | c | c | c |}
\hline
$Q$ & $R$ & $Q \lor R$ \\ \hline \hline
T & T & T \\
T & F & T \\
F & T & T \\
F & F & F \\
\hline
\end{truthtabular}
\end{document}
Why does the leading hline cause problems in the defined environment? What can be done to avert the problems?
Best Answer
You have a spurious pair of braces in your definition.
I slightly improved your table, using
\\hhline
for the double line, and I propose another layout: