Math & ScienceMultiline Text in Display Math

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
maxmax
Posts: 29
Joined: Sat Sep 03, 2011 11:19 am

Multiline Text in Display Math

Post by maxmax »

Hey folks,

i was wondering if its possible to do the following in a better way:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\begin{document}
  \begin{align*}
    a&=b &\Rightarrow &\text{ some fancy text} \\
    c&=d &\Rightarrow &\text{ some fancy, much longer explanation which} \\
    & & &\text{ does not fit into one line but should} \\
    & & &\text{ be aligned to the rest of the text}
  \end{align*}
\end{document}
which should look like

Code: Select all

 a = b  => some fancy text
 c = d  => some fancy, much longer explanation which
          does not fit into one line but should
          be aligned to the rest of the text
Since the code above is definitely not 'good', i hope there is a better way to do it.

Thanks in advance,
Max
Last edited by maxmax on Sat Sep 03, 2011 12:44 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Multiline Text in Display Math

Post by localghost »

If you want text to be wrapped into several lines, you can often simply use a \parbox of a certain width.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}   % loads »amsmath«

\begin{document}
  \begin{align*}
    a &= b &\Rightarrow &\ \text{some fancy text} \\
    c &= d &\Rightarrow &\ \text{\parbox[t]{8cm}{some fancy, much longer explanation which does not fit into one line but should be aligned to the rest of the text}}
  \end{align*}
\end{document}
The optional parameter for the box provides the correct alignment. Adjust the width of the box to your needs.

P.S.: Very nice minimal example.


Best regards and welcome to the board
Thorsten
maxmax
Posts: 29
Joined: Sat Sep 03, 2011 11:19 am

Re: Multiline Text in Display Math

Post by maxmax »

Thank you Thorsten,
this is exactly what i was looking for! :D
Post Reply