我想知道如何进行条件换行。每当出现错误消息“此处没有行结束”时,我都想使用命令\\
或\newline
命令禁用换行,否则启用它。
正如所建议的,我现在用一个最小的示例 tex 文件来解释我的问题。
我使用两个宏,它们允许我“吃掉”问题或答案,同时允许我在源中将它们保留在一起。例如,当我进行考试时,我会吃掉答案,只给出问题。
此示例导致以下错误消息:
LaTeX Error: There's no line here to end.
原因是我\\ [1ex]
在宏的开头有命令,\ans
。
如果我\\ [1ex]
从宏中删除该命令\ans
,错误就会消失。但不幸的是,第一个问题的答案并没有从新行开始。
我还想\\ [1ex]
在不需要时禁用该命令。例如,在第二个问题中,无论是否存在此命令,行为都是相同的。事实上,在某些情况下,此命令可能会创建不必要的额外空间。
\documentclass[12pt,a4paper]{article}
\newcommand{\quest}[1]{#1}
\newcommand{\eatquest}[0]{\renewcommand{\quest}[1]{}}
\newcommand{\ans}[1]{\\ [1ex] Answer: #1}
\newcommand{\eatans}[0]{\renewcommand{\ans}[1]{}}
\begin{document}
%\eatquest
%\eatans
\begin{enumerate}
\item
\quest{What is the effect of bad zeros? How can it be overcome?
}
\ans{
This results in poor performance of the system. The bad zeros
cannot be changed by feedback. The only way to change them is to
redesign the system (not controller) itself.
}
\item
\quest{This question is on 2-DOF pole placement controller
design. Answer the following:
\begin{enumerate}
\item In the class, a method was proposed to handle unstable 2-DOF
controllers. This method also has unstable pole-zero cancellation.
Why was this acceptable?
\end{enumerate}
}
\ans{A short answer is given now:
\begin{enumerate}
\item The pole and zero come for the same, ``identical'', source. In
fact, one can even say that this is NOT a case of pole-zero
cancellation.
\end{enumerate}
}
\end{enumerate}
\end{document}
答案1
使用\par\addvspace{1ex}
而不是\\[1ex]
\documentclass[12pt,a4paper]{article}
\newcommand{\quest}[1]{#1}
\newcommand{\eatquest}[0]{\renewcommand{\quest}[1]{}}
\newcommand{\ans}[1]{\par\addvspace{1ex}Answer: #1}
\newcommand{\eatans}[0]{\renewcommand{\ans}[1]{}}
\begin{document}
%\eatquest
%\eatans
\begin{enumerate}
\item
\quest{What is the effect of bad zeros? How can it be overcome?
}
\ans{
This results in poor performance of the system. The bad zeros
cannot be changed by feedback. The only way to change them is to
redesign the system (not controller) itself.
}
\item
\quest{This question is on 2-DOF pole placement controller
design. Answer the following:
\begin{enumerate}
\item In the class, a method was proposed to handle unstable 2-DOF
controllers. This method also has unstable pole-zero cancellation.
Why was this acceptable?
\end{enumerate}
}
\ans{A short answer is given now:
\begin{enumerate}
\item The pole and zero come for the same, ``identical'', source. In
fact, one can even say that this is NOT a case of pole-zero
cancellation.
\end{enumerate}
}
\end{enumerate}
\end{document}