2

How can I have multiple lines for the underbrace label?

--\/--
 A cost
 [A]

This is a some dummy equation to show what I already have.

\documentclass[twocolumn]{article}
\usepackage{color, etoolbox, lipsum, mathtools, geometry}
\usepackage{cuted, textcomp, setspace, longtable, tabularx, array}
\begin{document}
\twocolumn[
    {
            \begin{equation}
                c()=
                \begin{cases}
                    \underbrace{A'^{hr} \cdot Z^{\text{g}}}_{\textsubscript{A\ cost}}
                    + \underbrace{f(\Upsilon'^{hr}) \cdot ~'^{\text{get}} \cdot F^{ca}}_{\textsubscript{B\ cost}}
                    + \underbrace{B'^{\text{get}} \cdot F^{t}}_{\textsubscript{C\ cost}}
                    \right) & \text{if}\ B'^{\text{r}}=0 \\
                    1       & \text{otherwise.}
                \end{cases}
            \end{equation}
        }\bigskip]
\end{document}

With following output:

enter image description here

Wanted output, where under A cost there is [A] | under B cost there is [B] | under C cost there is [C]: enter image description here

alper
  • 1,389
  • 2
    Does https://tex.stackexchange.com/q/7503/263192 help? –  May 05 '22 at 10:49
  • Yes \\ did not helped but \atop\text{}help to solve the issue I was having – alper May 05 '22 at 10:53
  • 2
    Unrelated, note that \text should not be used for things like \text{get} etc. It does not do what you might think (write stuff upright, try addit \itshape before \begin{equation}). Use \textrm or \mathrm instead. – daleif May 05 '22 at 10:59
  • @daleif Thanks I was lost in the formats :-) text{} seemed more compact than mathrm thats why I used it. Should I do \text{\itshape get }} or just \atop\mathrm{}? Simple example would be appreciated. Is it also ok to use \textsubscript{} for the text under the underbrace – alper May 05 '22 at 11:19
  • 2
    As I mentioned use \mathrm or \textrm instead of \text. – daleif May 05 '22 at 11:51

2 Answers2

5

I sugggest you use \substack macros to create compactly spaced two-row items below each \underbrace.

Since you're dealing with a twocolumn layout, I think it's also necessary to insert an extra line break for the first case.

enter image description here

\documentclass[twocolumn]{article}
%\usepackage{color, etoolbox, lipsum, mathtools, geometry}
%\usepackage{cuted, textcomp, setspace, longtable, tabularx, array}
\usepackage{mathtools,geometry}
\begin{document}
\begingroup % limit scope of next instruction
\small
\begin{equation}
c()=
\begin{dcases*}
  \begin{aligned}[b]
  \underbrace{A^{\prime hr} Z^{\mathrm{g}}\mathstrut}_{%
        \substack{\text{A cost} \\ [\mathbf{A}]}}
&+ \underbrace{f(\Upsilon^{\prime hr}) ~^{\prime \mathrm{get}} F^{ca}}_{%
        \substack{\text{B cost} \\ [\mathbf{B}]}} \\
&+ \underbrace{B^{\prime \mathrm{get}} F^{t}}_{%
        \substack{\text{C cost} \\ [\mathbf{C}]}}
 \end{aligned} 
    & if $B^{\prime \mathrm{r}}=0$ \\
  1 & otherwise.
\end{dcases*}
\end{equation}
\endgroup
\end{document}
Mico
  • 506,678
  • Thanks for this golden approach. Could I switch 1 and the upper equation? I am not that could also help to make it more compact or advices – alper May 05 '22 at 21:35
  • @alper - Please clarify what you mean by "switch 1 and the upper equation". Do you maybe ask how to place the equation number on the first line? – Mico May 06 '22 at 00:48
  • Example output is illustrated https://gist.github.com/avatar-lavventura/f377410c93dc870b76ae895e1b6351df?permalink_comment_id=4157321#gistcomment-4157321. Just 1 otherwise moved into first line – alper May 06 '22 at 08:43
2

Use the array environment. By the way some codes are improved and some mistake are revised.

\documentclass[twocolumn]{article}
\usepackage{color, etoolbox, lipsum, mathtools, geometry}
\usepackage{cuted, textcomp, setspace, longtable, tabularx, array}
\begin{document}
\twocolumn[
    {
            \begin{equation}
                c()=
                \begin{cases}
                    \underbrace{A'^{\mathrm{hr}} \cdot Z^{\mathrm{g}}}_{\begin{array}{c}A\text{ cost}\\[-0.5ex] [\mathbf{A}]\end{array}}
                    + \underbrace{f(\Upsilon'^{\mathrm{hr}}) \cdot ~'^{\mathrm{get}} \cdot F^\mathrm{ca}}_{\begin{array}{c}B\text{ cost}\\[-0.5ex] [\mathbf{B}]\end{array}}
                    + \underbrace{B'^{\mathrm{get}} \cdot F^{\mathrm{t}}}_{\begin{array}{c}C\text{ cost}\\[-0.5ex] [\mathbf{C}]\end{array}}
                    & \text{if}\ B'^{\mathrm{r}}=0; \\
                    1       & \text{otherwise.}
                \end{cases}
            \end{equation}
        }\bigskip]
\end{document}

enter image description here

M. Logic
  • 4,214
  • Thanks. I appreciated you revision. Should I convert {hr} into {\mathrm{hr}} as well? Is it possible to make space between [A] [B] [C] and 1 smaller – alper May 05 '22 at 13:10
  • Will this equation fit inside the width of a single column in a two-column document? – Mico May 05 '22 at 13:14
  • @alper If hr and g are the same type, then hr should be in mathrm too. Adding more spaces between [A] and 1 isn’t advised otherwise it will be confufused. – M. Logic May 05 '22 at 16:58
  • @Mico It’s a new question. – M. Logic May 05 '22 at 17:00
  • @M.Logic got it, I thought you left {hr} without mathrm{} in purpose since it was 2 characters; so I can convert them into {\mathrm{hr}} without a problem – alper May 05 '22 at 18:06