4

I want the text under an underbrace in mathmode to 1. Have linebreaks. 2. Be raggedright 3. Remain centered with respect to the midpoint of the underbrace.

I have tried with the two methods in the following code, but without success:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\sometext}{Given the conditions we impose}

\begin{document}
With \textbackslash mbox:
\begin{equation}\nonumber
x
\underbrace{=}_{%
\mbox{%
\parbox[c]{2cm}{%
\raggedright
\scriptsize
\sometext
}
}
}
y
\end{equation}
With amsmath \textbackslash text:
\begin{equation}\nonumber
x
\underbrace{=}_{%
\text{%
\parbox[c]{2cm}{%
\raggedright
\sometext
}
}
}
y
\end{equation}
\end{document}

enter image description here

5
  • 1
    In order for the \parbox to know how to break lines, a width is necessary. Therefore, the moment you set it to 2cm, the boxes' width becomes that and the whole box (white space included) is centered with respect to the underbrace (change \mbox for \fbox to see the idea). You can avoid this in two ways. 1. Avoid the \parbox and break lines on your own, like suggested below. 2. Choose and appropiate size for each case. 1.28cm or 1.66cm seem to give a nicer picture.
    – mendus
    Feb 19, 2019 at 12:34
  • Ok. I see. Could the margins of the \mbox and \fbox be set to zero, or at least to be symmetric to the left and right?
    – Rasmus
    Feb 19, 2019 at 15:02
  • As @mendus (and, implictly, Steven, in his answer) has already remarked, the problem is (almost) trivial if you accept the condition that all line breaks be specified manually; it becomes significantly tougher if you insist on automatic line-breaking. Before posting a long and complicated answer, I’d like to know if the requirement that line breaks are automatically found by TeX is really an esential part of your question.
    – GuM
    Feb 19, 2019 at 15:48
  • I'm not gonna use this extensively, so I can define the line breaks manually. I find it unsatisfying, though, that it seems complicated to get this done automatically :-)
    – Rasmus
    Feb 19, 2019 at 17:25
  • @Rasmus As far as I understand, the white space are not margins. If you want it ragged right, the space will be on the right. If you want to automate it, I would suggest centering the text and removing the width of the box with \makebox[0pt]{<center aligned parbox>}
    – mendus
    Feb 20, 2019 at 8:22

2 Answers 2

5

For a column this narrow, I think manual linebreaks work better. Then you don't have to specify an arbitrary column width (such as 2cm). In addition, using a \makebox[0pt] box allows for the underset text to not disturb the equation spacing (though the underbrace itself does a bit)

\documentclass{article}
\usepackage{amsmath,stackengine}
\setstackEOL{\\}
\newcommand{\sometext}{Given the conditions we impose}
\begin{document}
\[
x \underbrace{=}_{%
\makebox[0pt]{\tiny\Longunderstack[l]{Given the\\conditions\\we impose}}
}y
\]
\end{document}

enter image description here

With a little more work, you could restore the natural math spacing of the = sign, though perhaps this is not important.

\documentclass{article}
\usepackage{amsmath,stackengine}
\setstackEOL{\\}
\newcommand\undertext[3][3pt]{%
  \mathrel{\stackengine{#1}{$#2$}{$\underbrace{}_{%
  \makebox[0pt]{\tiny\Longunderstack[l]{#3}}}$}{U}{c}{F}{T}{L}}%
}
\begin{document}
\[
x \undertext{=}{Given the\\conditions\\we impose} y
\]
\end{document}

enter image description here

3

An approximative and rudimental solution. but it works. It is possible to fit the space between x and y fixing \hspace{-.5cm}.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
x\hspace{-.5cm}\underbrace{=}_{\mbox{\tiny{\begin{tabular}{cc} Given the\\conditions\\we impose\end{tabular}}}}\hspace{-.45cm}y
\]
\end{document}

You must log in to answer this question.

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