使用自定义命令时,章节标题后不需要空格

使用自定义命令时,章节标题后不需要空格

enter image description here

我已经使用 LaTeX 多年了,通常我可以自己回答问题或者借助 stack exchange。直到现在。我在章节标题后出现了一个奇怪的垂直空格(见图)。当我不使用自定义命令时,这种情况实际上不会发生\fillspace。但在后面的小节(这里未显示)中,即使我使用相同的命令\fillspace,也不会发生这种情况,因此这似乎不是一个常见问题。奇怪的是,在我为您提供的有关这个问题的最小示例代码中没有发生这种情况(原始代码是针对 25 页长的课程...)。我创建和使用的另一个命令是\slv(它的作用相同,\\但可以防止反复出现“这里没有行结束”错误)。我怀疑我的新命令有一个细微的错误,但我就是想不通。

你知道我该如何删除这个无用的空白吗?如果需要的话,我可以和你分享整个代码。

在此先感谢您的回答,

祝好,

亨利

\documentclass[a4paper, 12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % load a font with all the characters
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}
\usepackage{stmaryrd}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsfonts}
\usepackage{appendix}
\usepackage{wasysym}
\usepackage{pifont}
\newcommand{\slv}{\leavevmode\\}
\newcommand{\exo}{\vspace{0.1cm}\slv \ding{46}\textbf{\underline{Exercises}}: \\ \vspace{0.1cm}\slv }
\newcommand{\exm}{\vspace{0.1cm}\slv $\triangleright$ \textit{\underline{Examples}}: \\ \vspace{0.1cm}\slv }
\newcommand{\rem}{ \vspace{0.1cm}\slv $\bell$ \textbf{\underline{Remarks:}} }
\newcommand{\fillspace}[1]{\vspace{#1cm}\slv \checkmark\slv \vspace{#1cm}\slv}
\begin{document}

blablabla

\section{Second degree equations}
Among the equations that are still easily solvable are the second degree equations, which contain at least one second degree term and can generally be written\slv 
\fillspace{0.5}
These equations have between zero and two real solutions, as we will see later.\\
\exm 
1) Let us start from the equation $5x^2+3x-8=0$. We have\\
\vspace{1cm}\\
2) For the equation $2y^2+9=0$, we have\\
\vspace{1cm}\\
3) If we have something like $z^2-7z-3=5z^2-12$, we can transform the equation into\\
\vspace{1cm}\\
and thus we have\\blablabla...

\end{document}

enter image description here

答案1

我删除了\\您示例中的所有内容,除了末尾用于标记段落中间换行符的情况(这是唯一应该使用的情况),这样间距就更合理了。最好使用定义标题的功能,而不是仅使用带下划线的文本和间距,因为这样 latex 会处理标题周围的分页符,但这里我只关注间距。

\documentclass[a4paper, 12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % load a font with all the characters
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}
\usepackage{stmaryrd}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsfonts}
\usepackage{appendix}
\usepackage{wasysym}
\usepackage{pifont}
%no!!! \newcommand{\slv}{\leavevmode\\}
\newcommand{\exo}{%
\par\vspace{0.1cm}%
\ding{46}\textbf{\underline{Exercises}}:\par\vspace{0.1cm}}
\newcommand{\exm}{%
\par\vspace{0.1cm}
$\triangleright$ \textit{\underline{Examples}}:\par
\vspace{0.1cm}}
\newcommand{\rem}{\par\vspace{0.1}$\bell$ \textbf{\underline{Remarks:}} }
\newcommand{\fillspace}[1]{\par\vspace{#1cm}\checkmark\par\vspace{#1cm}}
\begin{document}

blablabla

\section{Second degree equations}
Among the equations that are still easily solvable are the second degree equations, which contain at least one second degree term and can generally be written
\fillspace{0.5}
These equations have between zero and two real solutions, as we will see later.

\exm 
1) Let us start from the equation $5x^2+3x-8=0$. We have

\vspace{1cm}
2) For the equation $2y^2+9=0$, we have

\vspace{1cm}
3) If we have something like $z^2-7z-3=5z^2-12$, we can transform the equation into

\vspace{1cm}
and thus we have\\blablabla...

\end{document}

答案2

根据@David Carlisle 的建议做了一些修改后,我按照以下方式编写了代码,并添加了一些自定义结构的其他测试。有时我需要一个命令来留下一些空白,以便我的学生可以手动填写公式(这是命令 \sv 的作用)。您对此有更好的建议吗?

\documentclass[a4paper, 12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % load a font with all the characters
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{float}
\usepackage{stmaryrd}
\usepackage[margin=0.8in]{geometry}
\usepackage{amsfonts}
\usepackage{appendix}
\usepackage{wasysym}
\usepackage{pifont}
\newcommand{\sv}[1]{\par \vspace{#1cm}}
\newcommand{\exo}{%
\par\vspace{0.1cm}%
\paragraph{\ding{46} Exercises}:\par\vspace{0.1cm}}
\newcommand{\exm}{%
\par\vspace{0.1cm}
\paragraph{$\triangleright$ Examples}:\par
\vspace{0.1cm}}
\newcommand{\rem}{\par\vspace{0.1}\paragraph{$\bell$ Remarks}:}
\newcommand{\fillspace}[1]{\par\vspace{#1cm}\par\checkmark \par\vspace{#1cm}}
\begin{document}

blablabla

\section{Second degree equations}
Among the equations that are still easily solvable are the second degree equations, which contain at least one second degree term and can generally be written
\fillspace{0.5}
\par These equations have between zero and two real solutions, as we will see later.

\exm 
\par 1) Let us start from the equation $5x^2+3x-8=0$. We have

\sv{1}
\par 2) For the equation $2y^2+9=0$, we have

\sv{1}
\par 3) If we have something like $z^2-7z-3=5z^2-12$, we can transform the equation into

\sv{1}
\par and thus we have \sv{1}
\exo
Find the coefficients $a$, $b$ and $c$ in the following equations:\\
\sv{0.1}
\begin{tabular}{ll}
a) $2x^2-5x+11=0$ \hspace{4cm} & b) $3t^2-14=0$\\
\sv{0.1}\\
c) $-3w^2+11=8w$ & d) $-2x^2+4x-13=3x^2+9x$\\   
\end{tabular}\\
\end{document}

相关内容