In latex how to escape "{" in \verb in tabularx environmnet?

Viewed 42

I tried \verb|\{|, and it will print \{. If using \verb|{| without the backslash, an error would occur that says ! File ended while scanning \TX@get@body

Use the following to replicate this error on Overleaf or WinEdt:

\documentclass{article}
\usepackage{tabularx}

\begin{document}
\begin{table}
  \begin{tabularx}{\textwidth}{ll}
    \hline
    \verb|{| & Error. \\ % The use of \verb|{| here generates the error!
    \hline
  \end{tabularx}
\end{table}
\end{document}

I the above code, "\verb|{|" will generate the error.

With the kind help from samcarter_is_at_topanswers.xyz, I understand now that "{" can be displayed in tabularx using \listinline{{}. But this gives a plain-text style "{". Is there a way to make the "{" more code style? See the below picture for comparison.what I am looking for

1 Answers

You can use the listings package:

\documentclass{article}
\usepackage{tabularx}
\usepackage{listings}

\begin{document}
\begin{table}
  \begin{tabularx}{\textwidth}{lX}
    \hline
    \lstinline{\}} & Error. \\
    \hline
  \end{tabularx}
\end{table}
\end{document}

enter image description here

Related