我有一个居中的图形标题。这是我的代码示例:
\begin{figure}[!htb]
\centering
\includegraphics [width=\textwidth]{photo}
\caption{ This is my caption. I want the following two words: "TeX LaTeX" to be in the same line. }
\label{fig:2_2_0}
\end{figure}
我希望单词“TeX”和“LaTeX”始终位于同一行。但是,如果我输入:
"TeX \nolinebreak LaTeX"
正如我总是做的那样,它返回一个错误(“段落在标题完成之前结束”)。
我怎样才能做到这一点?
答案1
可以保护\nolinebreak
,如``\TeX{} \protect\nolinebreak\LaTeX''
。但是,还有另一种方法:
通过在 中放置不可中断的文本\mbox{}
,文本中就不会出现换行符。框是不可中断的实体,既可以换行,也可以换页。
\documentclass{article}
\usepackage[margin=5.5cm]{geometry}
\usepackage[demo]{graphicx}
\begin{document}
FIXED VERSION
\begin{figure}[!htb]
\centering
\includegraphics [width=\textwidth]{photo}
\caption{ This is my caption. I want the following two words: ``\mbox{\TeX{} \LaTeX}'' to be in the same line. }
\label{fig:2_2_0}
\end{figure}
ORIGINAL VERSION
\begin{figure}[!htb]
\centering
\includegraphics [width=\textwidth]{photo}
\caption{ This is my caption. I want the following two words: ``\TeX{} \LaTeX'' to be in the same line. }
\label{fig:2_2_0}
\end{figure}
\end{document}