9

Been dealing with TeX for a few weeks and it's great! Now I want to do a descriptive equation like this:

Descriptive equation Tried using \equation*, and also \align, but no luck. Using brackets right into the code as in

\begin{equation*}
[\text{What I want to do is this}]= ....
....
\end{equation*}

leads to a single line equation with small brackets.

Is there any other way I can do it?

Thank you in advance.

1
  • You can probably use TikZ. Commented Aug 2, 2018 at 19:09

3 Answers 3

8

Well what you could do is simply use a bmatrix

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
  \begin{bmatrix}
    \text{What I want to} \\
    \text{do is this}
  \end{bmatrix}
  = +
  \begin{bmatrix}
    \text{A balance equation} \\
    \text{I need}
  \end{bmatrix}
  -
  \begin{bmatrix}
    \text{Into brackets that} \\
    \text{describe things}
  \end{bmatrix}
  -
  \begin{bmatrix}
    \text{In two rows between} \\
    \text{big brackets}
  \end{bmatrix}
\end{equation*}

\end{document}

It's maybe a bit of a hack in some ways since they're probably not really matrices, but it looks right.

enter image description here

2
  • 1
    +1. You may want to point out, though, that this method offers no assurance that the "equation" will fit within the textblock.
    – Mico
    Commented Aug 2, 2018 at 19:22
  • This is exactly what I needed. Thank you all for your help!
    – jvalzert
    Commented Aug 3, 2018 at 19:02
11

Here's a solution that allows for automatic line breaking in each of the "boxes". The material is automatically centered on each line. The \Centering instruction (provided by the ragged2e package) allows hyphenation and does a reasonably good job of balancing the line lengths within a box. (LaTeX's basic \centering instruction does not allow either hyphenation or line-length balancing.)

In the upper half of the following screenshot, I chose a common width of 0.2\textwidth for all four boxes. In the lower half, I reduced the widths of the first two boxes a bit.

enter image description here

\documentclass{article}
\usepackage{geometry}  % set page parameters suitably
\usepackage{ragged2e}  % for '\Centering' macro
\usepackage{array}     % for '\newcolumntype' macro
\newcolumntype{Q}[1]{% % box widths expressed as fractions of '\textwidth'
    >{\Centering\arraybackslash}p{#1\textwidth}}
\usepackage{amsmath}   % for 'bmatrix' environment
\newcommand\mybox[2]{%
    \begin{bmatrix}
    \begin{tabular}{@{}Q{#1}@{}} 
      #2
    \end{tabular}
    \end{bmatrix}}

\begin{document}
%% first attempt: uniform widths
\[ 
   \mybox{0.2}{What I want to do is this}
= +\mybox{0.2}{A balance equation I need}
  -\mybox{0.2}{Intro brackets that describe things}
  -\mybox{0.2}{In two rows between big brackets}
\]

%% second attempt: customized widths
\[ 
   \mybox{0.14}{What I want to do is this}
= +\mybox{0.17}{A balance equation I need}
  -\mybox{0.20}{Intro brackets that describe things}
  -\mybox{0.20}{In two rows between big brackets}
\]
\end{document}
6
  • 1
    I was working on something like this but your solution is, in my opinion, superior +1
    – Au101
    Commented Aug 2, 2018 at 19:24
  • 2
    I think as a user, I would prefer to specify line breaks manually and get the widths automatically computed, than to specify the widths manually and get automatic line-breaking. (In the latter case, at least the text ought to be justified, so that there aren't ugly spaces on each side as in the top figure.) The reason is that choosing line breaks is “discrete” and I can just try all reasonable options, while with specifying widths I'm never quite sure whether I've got it right. (Should it be 0.14 or 0.145? Or maybe 0.139?) Commented Aug 2, 2018 at 23:15
  • @ShreevatsaR - Thanks. A nice benefit of specifying the relative widths (and making LaTeX find suitable line breaks) is that one is pretty much guaranteed that the entire "equation" will fit within the text block, as long as the relative widths sum to less than ca 0.8\textwidth. The other two answers do not offer this assurance, virtually guaranteeing lots of fine-tuning of the text material. Which method -- hard-coding the line breaks, or making LaTeX choose the line breaks -- is better likely depends on the OP's real application, about which we know next to nothing so far, right?
    – Mico
    Commented Aug 3, 2018 at 5:19
  • @Mico Yes you're right; I agree that the OP's real application likely determines which method is better: hard-coding the widths, or making LaTeX choose the widths. :-) Was just pointing out that there are fewer (finitely many) choices for line breaks than for widths (a continuum, though technically finite constrained by machine precision and human patience). Commented Aug 3, 2018 at 20:39
  • I agree with @ShreevatsaR here. Fixing the width of each of the matrices would mean words breaking with hyphens, and don't seem cute.
    – jvalzert
    Commented Nov 30, 2022 at 0:08
9

This is in-line with Mico's answer suggesting to create your own environment - textmatrix - that provides some alignment flexibility (optional argument for alignment within the text column):

enter image description here

\documentclass{article}

\newenvironment{textmatrix}[1][c]
  {
  \left[
    \begin{tabular}{@{} #1 @{}}
  }{%
    \end{tabular}
  \right]
  }

\begin{document}

\[
  \begin{textmatrix}
    What I want to \\
    do is this
  \end{textmatrix}
  =
  \begin{textmatrix}[l]
    A balanced equation \\
    I need
  \end{textmatrix}
  +
  \begin{textmatrix}[r]
    into brackets that \\
    describe things
  \end{textmatrix}
  -
  \begin{textmatrix}
    in two rows between \\
    big brackets
  \end{textmatrix}
\]

\end{document}

You must log in to answer this question.

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