简体   繁体   English

在 latex 如何在 tabularx 环境中的 \verb 中转义“{”?

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

I tried \verb|\{|我试过\verb|\{| , and it will print \{ . ,它将打印\{ If using \verb|{|如果使用\verb|{| without the backslash, an error would occur that says ! File ended while scanning \TX@get@body如果没有反斜杠,则会出现错误消息! File ended while scanning \TX@get@body ! File ended while scanning \TX@get@body

Use the following to replicate this error on Overleaf or WinEdt:使用以下方法在 Overleaf 或 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|{|"我上面的代码,“\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{{}.在 samcarter_is_at_topanswers.xyz 的帮助下,我现在明白“{”可以使用 \listinline{{} 在 tabularx 中显示。 But this gives a plain-text style "{".但这给出了纯文本样式“{”。 Is there a way to make the "{" more code style?有没有办法让“{”更具代码风格? See the below picture for comparison.请参阅下图进行比较。 我在找什么

You can use the listings package:您可以使用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}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM