我正在编写遵循样式指南的论文模板。根据指南,文档的标题需要出现在几个地方。在某些地方,标题文本必须分成几行,在其他地方必须加下划线。
理想情况下,模板用户只需输入一次标题,同时定义将文本分成多行的最佳方式。对于以这种方式输入的标题,我很难删除换行符并应用下划线而不会弄乱文本。这是我目前所拥有的。
\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand{\removelinebreaks}[1]{%
\begingroup\def\\{\relax}#1\endgroup}
\newcommand{\Title}[1]{\gdef\TheTitleField{\removelinebreaks{#1}}}
\Title{This Is A Long Title\\
That Should Be Broken\\
Up Into Several Lines\\
Lets Add A Few Lines \\
To Make This Even Longer
}
\begin{document}
\TheTitleField
\vspace{1in}
\uline{\TheTitleField}
\end{document}
删除换行符并应用下划线以使文本在应在的位置换行的最佳方法是什么?
答案1
你是指这样的吗?
\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand{\removelinebreaks}[1]{%
\def\\{\relax}#1}
\newcommand{\Title}[1]{\gdef\OrigTitle{#1}}
\def\TitleUline{\uline{\OrigTitle}}
\def\TitleRLB{\removelinebreaks{\OrigTitle}}
\makeatletter
\def\TitleUlineRLB{%
\def\\{\relax}%
\protected@edef\tmp{\OrigTitle}%
\expandafter\uline\expandafter{\tmp}%
}
\makeatother
\begin{document}
\Title{This Is A Long Title\\
That Should Be Broken\\
Up Into Several Lines\\
Lets Add A Few Lines \\
To Make This Even Longer
}
\TitleRLB% remove line breaks
\vspace{1cm}
\TitleUline% underline
\vspace{1cm}
\TitleUlineRLB% underline and remove line breaks
\end{document}