8

I noticed a peculiar behavior of tabularx when using \verb. The following minimal working example illustrates the problem.

Note the wicked extra space introduced between test and {123}.

\documentclass{article}
\usepackage{tabularx}

\begin{document}

\verb|tabular|

\begin{tabular}{|l|}
\hline
\verb|\test{123}{}{} \foo{} \bar{}|\\
\hline
\end{tabular}

\verb|tabularx|

\begin{tabularx}{\columnwidth}{|X|}
\hline
\verb|\test{123}{}{} \foo{} \bar{}|\\
\hline
\end{tabularx}

\end{document}

enter image description here

It seems like the content of \verb|***| is parsed in the case of tabularx. This is best seen if \verb|| contains non-paired curly braces: \verb|open-brace:{|. This normally would not cause a problem. If used within tabularx, however, it leads to an error.

How can I use \verb normally within a tabularx? How can I get rid of these extra spaces?

4
  • 4
    On the console and in the .log-file I get the warning LaTeX Warning: \verb may be unreliable inside tabularx on input line 20. Dec 3, 2023 at 22:18
  • @UlrichDiez Ah, didn't pay attention to this. Is there an alternative way of printing code verbatim within tabularx? Or do I have to mimic the behavior of \verb, like this: \texttt{\textbackslash test\{123\}}...
    – normanius
    Dec 3, 2023 at 22:29
  • 3
    it'a not peculiar behaviour, it's a documented feature, see the tabularx manual. Dec 3, 2023 at 23:51
  • @DavidCarlisle True! I should have had a look at it. Sorry for framing the question this way.
    – normanius
    Dec 4, 2023 at 0:14

2 Answers 2

10

You can use \Verb from fancyvrb, but with the better definition provided by fvextra.

\documentclass{article}
\usepackage{tabularx}
\usepackage{fvextra}

\begin{document}

\Verb|tabular|

\noindent
\begin{tabular}{|l|}
\hline
\Verb|\test{123}{}{} \foo{} \bar{}|\\
\hline
\end{tabular}

\Verb|tabularx|

\noindent
\begin{tabularx}{\columnwidth}{|X|}
\hline
\Verb|\test{123}{}{} \foo{} \bar{}|\\
\hline
\end{tabularx}

\end{document}

enter image description here

3
\documentclass{article}
\usepackage{tabularx}

\begin{document}

\verb|tabular|

\begin{tabular}{|l|}
\hline
\verb|\test{123}{}{} \foo{} \bar{}|\\
\hline
\end{tabular}

\verb|tabularx|

\begin{tabularx}{\columnwidth}{|X|}
\hline
\texttt{\string\test\{123\}\{\}\{\} \string\foo\{\} \string\bar\{\}}\\
\hline
\end{tabularx}

\end{document}

enter image description here

Or try find some cool way to paste your code using this book :) https://github.com/AnMnv/eBook

1
  • That's odd - the curly brackets put inside \textt aren't in tt. Which is also why the later characters in the 2 examples don't line up
    – Chris H
    Dec 4, 2023 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .