2

How do I clean up my equations below? I would like the text "object motion probability" to not exceed the margin and the second line to be pushed to the left. This is how it looks like currently

enter image description here

\documentclass{article}
\usepackage[twocolumn,margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{lipsum}  

\begin{document}
\lipsum
\begin{align}
    \sum_{s,i,j,t} \lambda_1(\underbrace{||\hat{y}^t_\Psi - y^t||_2^2}_\text{human pose} + \underbrace{||\hat{x}_{\varphi,i}^t - x_i^t||_2^2}_\text{object pose}) + \lambda_2\underbrace{\hat{\alpha}^t_i \log \alpha^t_i}_{\mathclap{\text{object motion probability}}} \nonumber \\ + \lambda_1\underbrace{\delta_s^t||(\hat{y}^t_{\Phi,s} - y^t){\circ} (1-m_s)||_2^2}_\text{refined arms} + \lambda_2\underbrace{\hat{\beta}^t_{s,j} \log \hat{\beta}^t_{s,j}}_{\mathclap{\text{contact probability}}} \nonumber
\end{align}
\lipsum
\end{document}
1
  • Off-topic: Please all instances of || with \Vert.
    – Mico
    Aug 15, 2023 at 6:09

5 Answers 5

2

You can use the fleqn environment of the nccmath package in the following way:

\documentclass{article}
\usepackage[twocolumn,margin=2cm]{geometry}

\usepackage{mathtools,nccmath}
\usepackage{lipsum}  

\begin{document}
\lipsum
\begin{fleqn}
\begin{multline*}
    \sum_{s,i,j,t} \lambda_1(\underbrace{\lVert\hat{y}^t_\Psi - y^t\rVert_2^2}_\text{human pose} + \underbrace{\lVert\hat{x}_{\varphi,i}^t - x_i^t\rVert_2^2}_\text{object pose}) 
     + \lambda_2\underbrace{\hat{\alpha}^t_i \log \alpha^t_i}_{\mathclap{\text{object motion probability}}}\\
    + \lambda_1\underbrace{\delta_s^t\lVert(\hat{y}^t_{\Phi,s} - y^t)\circ (1-m_s)\rVert_2^2}_\text{refined arms} 
     + \lambda_2\underbrace{\hat{\beta}^t_{s,j} \log \hat{\beta}^t_{s,j}}_{\mathclap{\text{contact probability}}}
\end{multline*}
\end{fleqn}
\lipsum
\end{document}

enter image description here

4

enter image description here

The expression as written (just) fits if you set \mathindent to zero.

Note \lVert not||, you can use a * environment rather than \nonumber every line, and use _{\text{...}} not _\text{...} (the latter works by accident but is really weird and vastly complicates conversion of the expression to html or other formats.)

\documentclass{article}
\usepackage[twocolumn,margin=2cm]{geometry}
\usepackage[fleqn]{amsmath}
\setlength\mathindent{0pt}
\usepackage{mathtools}
\usepackage{lipsum}  

\begin{document}
\lipsum
\begin{multline*}
    \sum_{s,i,j,t} \lambda_1(\underbrace{\lVert\hat{y}^t_\Psi - 
      y^t\rVert_2^2}_{\text{human pose}} + \underbrace{\lVert\hat{x}_{\varphi,i}^t - 
         x_i^t\rVert_2^2}_{\text{object pose}}) + 
        \lambda_2\underbrace{\hat{\alpha}^t_i \log \alpha^t_i}_{\mathclap{\text{object motion probability}}} r \\
 + \lambda_1\underbrace{\delta_s^t\lVert(\hat{y}^t_{\Phi,s} - y^t){\circ} (1-m_s)\rVert_2^2}_\text{refined arms} + 
\lambda_2\underbrace{\hat{\beta}^t_{s,j} \log \hat{\beta}^t_{s,j}}_{\mathclap{\text{contact probability}}}
\end{multline*}
\lipsum
\end{document}
3

How about you split the equation at a sum symbol and keep each sub expression in separate line?

I would also suggest a small change inside each \underbrace. If you insert struts, you stretch contents vertically and push each annotation to the same level. The macro \xmathstrut (mathtools) has a parameter size that corresponds to height of a strut.

If you want subscript in multiple lines, try \substack. Its variant subarray (environment) can also control alignment. Since annotations are typeset in math (italics), you need to use \text{} in each row. This can be automated using \cellcollect and \endcellcollect (cellcoll) in the regular array.

Here's the code

\documentclass{article}
\usepackage[twocolumn,margin=2cm]{geometry}
\usepackage{array}
\usepackage{mathtools}
\usepackage{lipsum}
\usepackage{collcell}

\newcommand\textcell[1]{\text{\scriptsize#1}}
\NewDocumentEnvironment{xsubarray}{mb}{%
  \renewcommand\arraystretch{0.65}%
  \begin{tabular}{>{\collectcell\textcell}#1<{\endcollectcell}}#2\end{tabular}}{}
\newcommand\xxstrut[1][0.5]{\xmathstrut{#1}}


\begin{document}
\lipsum
\begin{equation*}
  \begin{split}
    \sum_{s,i,j,t} \mathrlap{\lambda_1 \Bigl(
    \underbrace{\xxstrut
    \lVert\hat{y}^t_\Psi - y^t\rVert_2^2}_{\text{human pose}}
    {}+{}
    \underbrace{\xxstrut
    \lVert\hat{x}_{\varphi,i}^t - x_i^t\rVert_2^2}_\text{object pose}
    \Bigr)} & \\
            & + \lambda_2 \Bigl(
              \underbrace{\xxstrut
              \hat{\alpha}^t_i \log \alpha^t_i}_{\mathclap{
              \begin{xsubarray}{c}object motion\\probability\end{xsubarray}}}
              {}+{}
              \underbrace{\xxstrut
              \hat{\beta}^t_{s,j} \log \hat{\beta}^t_{s,j}}_{\mathclap{
              \begin{xsubarray}{c}contact\vphantom{bj}\\probability\end{xsubarray}}}
              \Bigr) \\
            & + \lambda_1 \Bigl(
              \underbrace{\xxstrut
              \delta_s^t\lVert(\hat{y}^t_{\Phi,s} - y^t){\circ} (1-m_s)\rVert_2^2}_\text{refined arms}
              \Bigr).
  \end{split}
\end{equation*}
\lipsum
\end{document}

enter image description here

2

You can use a \substack directive to introduce a line break in the second argument of the \underbrace directive in question. Next, since there's no natural alignment point in the two rows, I'd use a multline environment instead of an align environment. Finally, do take care to assure that the text arguments of the \underbrace instructions in line 1 line up vertically.

enter image description here

\documentclass{article}
\usepackage[twocolumn,margin=2cm]{geometry}
\usepackage{mathtools}
% define a '\norm' macro:
\DeclarePairedDelimiter\norm\lVert\rVert
% define a typographic strut with height and depth of '\hat{x}^t_{\varphi,i}' 
\newcommand\mystrut{\vphantom{\hat{x}^t_{\varphi,i}}} 
\usepackage{lipsum} % filler text

\begin{document}
\lipsum[1] % filler text
\begin{multline*}
    \sum_{s,i,j,t} \lambda_1 \bigl(
    \underbrace{\norm{\hat{y}^t_\Psi - y^t}_2^2\mystrut}_{\text{human pose}}
    + \underbrace{\norm{\hat{x}_{\varphi,i}^t - x_i^t}_2^2}_{\text{object pose}}
    \bigr) 
    + \lambda_2\underbrace{\hat{\alpha}^t_i \log \alpha^t_i\mystrut}_{\mathclap{\substack{\text{object motion}\\ \text{probability}}}}  \\
    + \lambda_1\underbrace{\delta_s^t \norm{(\hat{y}^t_{\Phi,s} - y^t){\circ} (1-m_s)}_2^2}_{\text{refined arms}}
    + \lambda_2\underbrace{\hat{\beta}^t_{s,j} \log \hat{\beta}^t_{s,j}}_{\mathclap{\text{contact probability}}}
\end{multline*}
\lipsum[2] % more filler text
\end{document}
1
  • thank you, but is it possible to do something like \hspace{-1cm} ? I tried inserting it and it did nothing. I would very much prefer to utilize the horizontal space instead of using up more vertical space.
    – Kong
    Aug 15, 2023 at 7:18
0

You need to take into account the width of the text that goes beyond the underbrace and that you make zero with \mathclap.

You can also (locally) remove the \multlinegap.

\documentclass{article}
\usepackage[twocolumn,margin=2cm]{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{lipsum}

\newcommand{\ubrace}[2]{{\underbrace{#1}_{#2}}}

\begin{document}

\lipsum[1][1-4]
\begingroup\setlength{\multlinegap}{0pt}
\begin{multline*}
  \sum_{s,i,j,t}
    \lambda_{1}\bigl(\,\ubrace{\|\hat{y}^t_\Psi - y^t\|_2^2\vphantom{^{}_{j}}}
                              {\text{human pose}}
   +\ubrace{\|\hat{x}_{\varphi,i}^t - x_i^t\|_2^2}{\text{object pose}}\,\bigr)
   +\lambda_2\ubrace{\hat{\alpha}^t_i \log \alpha^t_i\vphantom{^{}_{\phi}}}
                    {\mathclap{\text{object motion probability}}}
   \hphantom{\scriptstyle\mathrm{bability}}
\\
   +\lambda_1\ubrace{\delta_s^t\|(\hat{y}^t_{\Phi,s}-y^t)\circ(1-m_s)\|_2^2\vphantom{^{}_{j}}}
                    {\text{refined arms}}
   +\lambda_2\ubrace{\hat{\beta}^t_{s,j} \log \hat{\beta}^t_{s,j}}
                    {\mathclap{\text{contact probability}}}
\hphantom{\scriptstyle\mathrm{ity}}
\end{multline*}
\endgroup
\lipsum[2][1-3]

\end{document}

Note the phantoms to get the same level of the underbraces and the \ubrace command; you can clearly see that the spacing of the + signs is wrong with \underbrace. Note also \bigl( and \bigr), together with the thin space to avoid clashes.

enter image description here

You must log in to answer this question.

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