0

I am trying to get both the text aligned with the header, and even verical spacing before and after equations.

My first version of the code returns aligned text, but uneven equation spacing:

\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}

This returns uneven spacing for equations: enter image description here

I tried some solutions for the spacing, such as the one in this question:

\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}

But this results in unaligned text: enter image description here

Am I doing something wrong in the code? Is there a solution or a workaround for this?

Thank you!

1 Answer 1

1

In your second example, it's not the text, but the rule in the header, that's misaligned. This seems to be caused by the linebreaks in the code added to fix the equation spacing being interpreted as whitespace in that context. It you comment out the linebreaks like this:

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

It seems to fix the problem.

(Notice I changed the values as well. Yours were uneven, but you may need to fiddle with them.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .