2

I want to center an equation inside an align environment, since it otherwise would push the other equations too far to the right, outside of my tcolorbox.

As suggested in this answer, one should be able to do so with the \mathclap command from mathtools.

Obviously this does not work here:

enter image description here

MWE:

% !TeX program=lualatex
\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{tcolorbox}
\usepackage[ngerman]{babel}

\begin{document}
\begin{figure}
    \begin{tcolorbox}
        \begin{align}
        \dot{\epsilon}^{\text{eq}} &= \sqrt{\frac{2}{3}\dot{\boldsymbol{\epsilon}}^{\text{p}}:\dot{\boldsymbol{\epsilon}}^{\text{p}}} && \text{(an equation in plasticity)} \\
        %
        \mathclap{
        \sigma^Y(z,\epsilon_{\gamma},\epsilon_{\alpha},T) = (1-f(z))\sigma^y_{\gamma}(\epsilon_{\gamma},T)+f(z)\sigma^y_{\alpha}(\epsilon_{\alpha},T)
        }\label{gln:ultimate-stress-iso}
        \end{align}
    \end{tcolorbox}
\end{figure}
\end{document}
  • 3
    Actually it is doing exactly what it is suppose to. It is centering the equation at the current point. There are not alignment markers on this line, thus we have a single left hand part of an alignment column, aka the mathclap is centered under the left part of the = in the line above, as seen in the image. BTW: you should never ever use \text like this, it does not do what you think. Uwe \mathrm or \textup (long story short, \text will output italic text is the surrounding context is italic, like inside a theorem, we do not want that, we want upright always) – daleif Apr 3 '18 at 19:47
  • Is there a way to manually place an "alignment marker" on the center of the line? I ended up inserting a \hspace{6cm} inside the \mathclap for now, which at least approximately centers the equation and leaves the rest as is. – Christoph90 Apr 4 '18 at 8:39
  • @daleif As a side note: Is there any other drawback from the misuse of \text than the one you mentioned? I never typeset math in an italic environment. – Christoph90 Apr 4 '18 at 8:46
  • 2
    The main problem is education. In the end you probably end up passing on your code to others, and then they think this is the proper method to use. Or, what happens if a publisher ask you to change some layouts, so some of these end up being italic. Better to remove bad habits than to have to clean up afterwards. It is also when others see your code on this site, they'll think this is the proper way to get stuff upright, but it is not. Another thing would be if the math and text font differed a lot. – daleif Apr 4 '18 at 8:52
  • 1
    Exactly, therefore it is not a good idea to use \text for anything other than textual comments. I often never use \text, add it inside relevant macros (for example I have one that produces \qquad\text{#1}, making the code cleaner) – daleif Apr 4 '18 at 9:10
4

In this case I guess it would be better to either don't use \mathclap at all and remove the && prior to your text (as this is really pushing your equations to the left) or to use a \mathllap on some parts of the second equation. The following is an example showing both options.

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{tcolorbox}
\usepackage[ngerman]{babel}

\begin{document}
\begin{figure}
    \begin{tcolorbox}
        \begin{align}
        \dot{\epsilon}^{\text{eq}} &=
        \sqrt{\frac{2}{3}\dot{\boldsymbol{\epsilon}}^{\text{p}}:\dot{\boldsymbol{\epsilon}}^{\text{p}}}
        \quad\text{(an equation in plasticity)} \\
        %
        \mathllap{\sigma^Y(z,\epsilon_{\gamma},\epsilon_{\alpha},}T) &= (1-f(z))\sigma^y_{\gamma}(\epsilon_{\gamma}^,T)+f(z)\sigma^y_{\alpha}(\epsilon_{\alpha},T)
        \label{gln:ultimate-stress-iso}
        \end{align}
    \end{tcolorbox}
    \begin{tcolorbox}
        \begin{align}
        \dot{\epsilon}^{\text{eq}} &=
        \sqrt{\frac{2}{3}\dot{\boldsymbol{\epsilon}}^{\text{p}}:\dot{\boldsymbol{\epsilon}}^{\text{p}}}
        \quad\text{(an equation in plasticity)} \\
        %
        \sigma^Y(z,\epsilon_{\gamma},\epsilon_{\alpha},T) &= (1-f(z))\sigma^y_{\gamma}(\epsilon_{\gamma}^,T)+f(z)\sigma^y_{\alpha}(\epsilon_{\alpha},T)
        \label{gln:ultimate-stress-iso}
        \end{align}
    \end{tcolorbox}
\end{figure}
\end{document}

enter image description here

Like you found out in your comment, you could as well use \mathrlap on some parts of the long equation:

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{tcolorbox}
\usepackage[ngerman]{babel}

\begin{document}
\begin{figure}
    \begin{tcolorbox}
        \begin{align}
        \dot{\epsilon}^{\text{eq}} &=
        \sqrt{\frac{2}{3}\dot{\boldsymbol{\epsilon}}^{\text{p}}:\dot{\boldsymbol{\epsilon}}^{\text{p}}}
        &&\text{(an equation in plasticity)} \\
        %
        \sigma^Y(z,\epsilon_{\gamma},\epsilon_{\alpha},T) &=
        (1-f(z))\sigma^y_{\gamma}(\epsilon_{\gamma}^,T)+\mathrlap{f(z)\sigma^y_{\alpha}(\epsilon_{\alpha},T)}
        \label{gln:ultimate-stress-iso}
        \end{align}
    \end{tcolorbox}
\end{figure}
\end{document}
  • I'd prefer the text behind the equations to be aligned via &&. There are actually more relatively short equations with text behind them and having these descriptions aligned looks better... – Christoph90 Apr 4 '18 at 8:38
  • 1
    Your answer made me realize, I can get exactly what I want, if I just put the last summand of the second equation inside \mathrlap. Maybe you want to add that to your answer so I can accept it? – Christoph90 Apr 4 '18 at 10:08
3

I think the real remedy consists in (a) not using \mathclap and, more importantly, (b) not using align. Instead, use a gather environment.

Separately, consider using \tfrac ("text style fraction") in the first equation.

And, since you appear to be using LuaLaTeX, don't write \boldsymbol{...}. Instead, be sure to load the unicode-math package and to write \symbf{...}. Similarly, don't write \text{p} and \text{eq}. Instead, write \symup{eq} and symup{p}.

enter image description here

% !TeX program=lualatex
\documentclass{scrartcl}
\usepackage{mathtools}
\usepackage{tcolorbox}
\usepackage{unicode-math}
\begin{document}

\begin{tcolorbox}
\begin{gather}
\dot{\epsilon}^{\symup{eq}} 
= \sqrt{\tfrac{2}{3}\dot{\symbf{\epsilon}}^{\symup{p}}:
  \dot{\symbf{\epsilon}}^{\symup{p}}} 
\qquad\text{(an equation in plasticity)} \\
\sigma^Y(z,\epsilon_{\gamma},\epsilon_{\alpha},T) 
= (1-f(z))\sigma^y_{\gamma}(\epsilon_{\gamma},T)
  +f(z)\sigma^y_{\alpha}(\epsilon_{\alpha},T)
\label{gln:ultimate-stress-iso}
\end{gather}
\end{tcolorbox}
\end{document}
  • Very compliments for both the two answers.+1. – Sebastiano Apr 3 '18 at 21:22
  • @Sebastiano - Muchas gracias! – Mico Apr 3 '18 at 21:23
  • @Mico Thanks for the hints on the unicode-math commands. However, I specifically asked for align since I want all (there are more) equations except the overlong second aligned at =. It looks messy otherwise. – Christoph90 Apr 4 '18 at 8:14
  • 1
    @Christoph90 - In that case, you should definitely go with the solution shown in equations 3 and 4 of @skillmon's answer. – Mico Apr 4 '18 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.