2

I want to have the beginning and end of a tabularx table appear only in some cases, but this does not seem to be possible. I get a "Runaway argument error". Why is wrong, or is this kind of construction impossible?

Here is a minimal example:

\documentclass[a4paper,12pt]{book}%

\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{tabularx}
\usepackage{ifthen}

\newboolean{thing}

\begin{document}
\setboolean{thing}{false}

\chapter*{Testchapter}
\ifthenelse{\boolean{thing}}{}{\begin{tabularx}{7cm}{|c|X|}}
3&5\\
\ifthenelse{\boolean{thing}}{}{\end{tabularx}}

\end{document}

(Of course, in my real document the "3&5\" line is replaced with something that is not a table in the cases where "thing" is true.)

1 Answers1

0

The tabularx environment is scanned entirely (up to \end{tabularx}) scans its entire body at once before processing it. So, you can't break up \begin{tabularx} from \end{tabularx} the way you're doing it. Including it as a whole during conditioning is an option:

enter image description here

\documentclass{article}

\usepackage{tabularx,etoolbox}

\newbool{thing}

\begin{document}

\boolfalse{thing}

Before

\ifbool{thing}
  {3 and 5}
  {%
  \begin{tabularx}{7cm}{ | c | X | }
    3 & 5 \\
  \end{tabularx}
  }%

After

\end{document}
Werner
  • 603,163