0

I am writing my thesis with the classicthesis package. This package uses fleqn to justify equations:

\PassOptionsToPackage{fleqn}{amsmath} % Math environments and more by the AMS 

However, the center environment is not to the left. I would like to create a new environment, similar to center, in which the text is aligned with the equations.

I considered using the equation* enviroment to write the text (i.e., with the \text command), however that gives me problems, and I don't think it's a very good solution. More specifically: the endlines must be specified manually (annoying/requires me to decide where its best to break the text), and the alignment is off (right justified?). For example:

enter image description here

Code here is simply: \begin{align*} \text{text...}\\ \text{text...}\end{align*}

Any suggestion how to do that?

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}

\PassOptionsToPackage{fleqn}{amsmath} % align left eqs
 \usepackage{amsmath}

\begin{document}

This algorithm never terminates:

\begin{equation*}
    x=x+1
\end{equation*}

And this text is not to the left:

\begin{center}
    I am not well-behaved.
\end{center}

\end{document}

Which results in (note how the text does not align with the equation):

enter image description here

Thanks!

12
  • Please provide code and not just images. We have not idea as to what you are actually doing here.
    – daleif
    Jun 18, 2021 at 13:46
  • Why not \begin{equation*}\text{the text}\end{equation*}?
    – egreg
    Jun 18, 2021 at 13:47
  • Hi @daleif . Sorry, I'll try to do my best. Unfortunately, I really have no idea where classicthesis does this, so I would have to paste a very large preamble. I'll just paste the code for the equations maybe?
    – olinarr
    Jun 18, 2021 at 13:58
  • @egreg I considered that, however, there are two issues with that. The first one is that I would have to break the lines manually (not fatal, but if there was another solution, I'd prefer that). The second one is that there is some vertical spaces between the text and the equations. This vertical space is not there with the ``center'' environment. I like it that way, and if there was a way to align center instead, I'd prefer that one. But if all else fails, I'll do as you suggest. Thanks!
    – olinarr
    Jun 18, 2021 at 14:00
  • 1
    Now you know why using random templates is not always a good idea.
    – daleif
    Jun 18, 2021 at 14:06

1 Answer 1

2

Well, first off, center isn't really an environment that should be showing up in your document—it's more something that should be used in building other environments/commands that have semantic meaning.

Now, the next thing is to understand how center works. The definition for center is¹:

\NewDocumentEnvironment{center}{}{%
   \begin{trivlist}\centering\item\relax
}
{%
   \end{trivlist}%
}

What we're doing is creating a single-item trivlist²,³ and applying the \centering definitions to it. \centering, in turn is:

\DeclareRobustCommand\centering{%
  \let\\\@centercr % ❶
  \rightskip\@flushglue\leftskip\@flushglue % ❷
  \finalhyphendemerits=\z@ % ❸
  \parindent\z@\parfillskip\z@skip} % ❹ 

This is fairly straightforward: It makes sure that \\ starts a new line in the paragraph⁴ ❶, sets the left and right margins to expand equally ❷, makes sure that we don't have the paragraph stretched out an extra line to avoid a hyphenation on the penultimate line⁵ ❸ and finally make sure that we don't get a first-line indent and that there's not extra space on the right for the last line. ❹

So we want to modify this to change the \leftskip to no longer be \@flushglue but instead follow the fleqn indent that you have for paragraphs.⁶ Here's our new definition.

\NewDocumentEnvironment{somesemanticenvironmentname}{}{%
   \begin{trivlist}
      \let\\\@centercr 
      \rightskip\@flushglue\leftskip\mathindent
      \finalhyphendemerits=\z@ 
      \parindent\z@
      \item\relax
}
{%
   \end{trivlist}%
}

  1. This is not the actual definition. I rewrote the code which, in the LaTeX source defines the center environment using primitive \def commands to use idiomatic LaTeX declarations.

  2. trivlist is another one of those environments that should never appear directly in a document's code. It's used for building various displayed text environments like quotation and verse among others. It lets us easily do things like nested quotation environments or have these things appear in an enumerate with the correctly adjusted margins.

  3. The original code uses \trivlist\endtrivlist instead of \begin{trivlist}\end{trivlist}. In the context of defining an environment, the former syntax is nearly the same since we'll already have the grouping that comes from \begin{}\end{} applied. However, with the addition of the hook interfaces for environments that are now part of LaTeX, when defining new code, unless you explicitly do not want hooks applied, you should use the environment syntax when wrapping up an environment in another environment definition. It's unlikely anyone is using hooks on trivlist but it's probably worth keeping the option open.

  4. This is why putting \centering in a p-column in a tabular often causes problems. If you're in the final column of the row, \\ won't mean end the row, but break a line in the paragraph.

  5. This is discussed in the answer to exercise 14.32 in The TeXbook.

  6. You can find this amount in fleqn.clo which identifies it as \mathindent.

1
  • This works exactly as intended and your answer is super detailed. Thank you very much!
    – olinarr
    Jun 18, 2021 at 15:51

You must log in to answer this question.

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