文本与标题对齐,且公式前后有垂直间距

文本与标题对齐,且公式前后有垂直间距

我试图使文本与标题对齐,甚至使方程式前后具有垂直间距。

我的第一个版本的代码返回对齐的文本,但不均匀的方程间距:

\documentclass[12pt,openright,twoside]{book}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{pdflscape}
\usepackage{newtxtext}
\usepackage[varvw]{newtxmath}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage{titlesec}
\usepackage[nottoc]{tocbibind}
\usepackage{titleps}


\titleformat{\chapter}[display]
{\bfseries\Huge}
{}
{-7ex}
{\titlerule
    \vspace{2ex}%
    \filright
    \ifnum\value{chapter} > 0
    \Huge\arabic{chapter}.
    \else 
    \fi
}
[\vspace{2ex}%
\titlerule]

\newpagestyle{main}{%
    \setheadrule{10pt}%
    \headrule
    \sethead[\textit{\thesection.\hspace{4pt}\sectiontitle}][][\thepage]%headers on even page (left-centre-right)%
    {\thepage}{}{\textit{\thechapter.\hspace{4pt}\chaptertitle}}% headers on odd pages
    %\setfoot{}{\thepage}{}
}
\pagestyle{main}


\geometry{
    a4paper,
    total={210mm,297mm},
    left=25.0mm,
    right=25.0mm,
    top=25.0mm,
    bottom=30.0mm,
}



\begin{document}
    \chapter{This is a chapter}
    \newpage
    This is aligned text. This is aligned text. This is aligned text. This is aligned text. This is aligned text. This is aligned text. 
    
Here is an example of an equation:

\begin{align}
    n_i=n; && n_e=n e^{e\phi(\mathbf{x})/k_BT},
    \label{1.2}
\end{align}

\noindent
This is uneven spacing.


\end{document}

返回方程的不均匀间距: 在此处输入图片描述

我尝试了一些解决间距问题的方法,比如这个问题

\documentclass[12pt,openright,twoside]{book}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{pdflscape}
\usepackage{newtxtext}
\usepackage[varvw]{newtxmath}
\usepackage{multicol}
\usepackage{mathtools}
\usepackage{titlesec}
\usepackage[nottoc]{tocbibind}
\usepackage{titleps}

\titleformat{\chapter}[display]
{\bfseries\Huge}
{}
{-7ex}
{\titlerule
    \vspace{2ex}%
    \filright
    \ifnum\value{chapter} > 0
    \Huge\arabic{chapter}.
    \else 
    \fi
}
[\vspace{2ex}%
\titlerule]
\newpagestyle{main}{%
    \setheadrule{10pt}%
    \headrule
    \sethead[\textit{\thesection.\hspace{4pt}\sectiontitle}][][\thepage]%headers on even page (left-centre-right)%
    {\thepage}{}{\textit{\thechapter.\hspace{4pt}\chaptertitle}}% headers on odd pages
    %\setfoot{}{\thepage}{}
}
\pagestyle{main}


\geometry{
    a4paper,
    total={210mm,297mm},
    left=25.0mm,
    right=25.0mm,
    top=25.0mm,
    bottom=30.0mm,
}
\expandafter\def\expandafter\normalsize\expandafter{%
    \normalsize  
    \setlength\abovedisplayskip{3pt}
    \setlength\belowdisplayskip{18pt}
    \setlength\abovedisplayshortskip{2pt}
    \setlength\belowdisplayshortskip{18pt}
}
\begin{document}
    \chapter{This is a chapter}
    \newpage
    This is unaligned text. This is unaligned text. This is unaligned text. This is unaligned text. This is unaligned text. This is unaligned text. 
Here is an example of an equation:
\begin{align}
    n_i=n; && n_e=n e^{e\phi(\mathbf{x})/k_BT},
    \label{1.2}
\end{align}
\noindent
This is even spacing.
\end{document}

但这会导致文本不对齐: 在此处输入图片描述

我在代码中做错了什么吗? 有解决方案或解决方法吗?

谢谢你!

答案1

在您的第二个示例中,错位的不是文本,而是标题中的规则。这似乎是由于在代码中添加的换行符(用于修复公式间距)在该上下文中被解释为空格而导致的。您可以像这样注释掉换行符:

\expandafter\def\expandafter\normalsize\expandafter{%
    \normalsize%
    \setlength\abovedisplayskip{16pt}%
    \setlength\belowdisplayskip{16pt}%
    \setlength\abovedisplayshortskip{2pt}%
    \setlength\belowdisplayshortskip{2pt}%
}

似乎问题已经得到解决。

(请注意,我也改变了这些值。你的值不均匀,但你可能需要摆弄它们。)

相关内容