\texttt
我正在使用这个命令的自定义版本这个答案要在我的文档中的等宽/打字机文本中启用换行符:
\newcommand*\justify{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
\hyphenchar\font=`\-% allowing hyphenation
}
% Allow linebreaks inside \texttt on '_' (also removes the need to escape underscores).
% Taken from https://tex.stackexchange.com/a/219497/293047
\catcode`_=12 %
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode`~=`_\lowercase{\endgroup\def~}{_\discretionary{}{}{}}%
\begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
\begingroup\lccode`~=`-\lowercase{\endgroup\def~}{-\discretionary{}{}{}}%
\catcode`/=\active
\catcode`_=\active
\catcode`.=\active
\catcode`-=\active
\justify\scantokens{#1\noexpand}%
\endgroup
}
\catcode`_=8 %
我在表格\texttt
中使用了多个实例\caption
。这在表格正下方的主文本中运行良好,但在我的表格列表中,等宽文本后的空格丢失了:
我需要做什么来确保空间被呈现?
以下是 MWE:
\documentclass{article}
\usepackage[english]{babel}
\newcommand*\justify{%
\fontdimen2\font=0.4em% interword space
\fontdimen3\font=0.2em% interword stretch
\fontdimen4\font=0.1em% interword shrink
\fontdimen7\font=0.1em% extra space
\hyphenchar\font=`\-% allowing hyphenation
}
% Allow linebreaks inside \texttt on '_' (also removes the need to escape underscores).
% Taken from https://tex.stackexchange.com/a/219497/293047
\catcode`_=12 %
\renewcommand{\texttt}[1]{%
\begingroup
\ttfamily
\begingroup\lccode`~=`/\lowercase{\endgroup\def~}{/\discretionary{}{}{}}%
\begingroup\lccode`~=`_\lowercase{\endgroup\def~}{_\discretionary{}{}{}}%
\begingroup\lccode`~=`.\lowercase{\endgroup\def~}{.\discretionary{}{}{}}%
\begingroup\lccode`~=`-\lowercase{\endgroup\def~}{-\discretionary{}{}{}}%
\catcode`/=\active
\catcode`_=\active
\catcode`.=\active
\catcode`-=\active
\justify\scantokens{#1\noexpand}%
\endgroup
}
\catcode`_=8 %
\begin{document}
\listoftables
\begin{table}[h]
\centering
\begin{tabular}{ll}
{} & Category\_Name \\
0 & Category 1 \\
\end{tabular}
\caption{The \texttt{Category\_Name} text feature}
\end{table}
\end{document}