Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to do something that seems relatively simple but I can't get it to work. Basically, I would like one of the columns in my math mode array to be text, so I am trying to use pre and post processing >{} and <{} like so

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{align}
    \begin{array}{{>{\text\bgroup}c<{\egroup}}@{:}c@{=}c}
    a & x^2 & x^2 \\
    b & y^2 & y^2 \\
    c & z^2 &  z^2
    \end{array}
    \end{align}
\end{document}

This leads to an "illegal character in array arg" error. What is the right way to do this?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You're close. In the modified example below, I'm using the array environment and define a special column type, L', that's automatically in text mode. The reason this works is because l, c, and r are automatically in math mode in an array environment.

Note the second intercolumn specifier, @{{}={}}: The pairs of {} curly braces before and after the = sign are there to inform TeX that the = sign is to be treated as a so-called mathrel object. In case this sounds a bit cryptic: mathord, mathbin, and mathrel objects each have different amounts of whitespace before and after them. An easy way to make TeX treat a = symbol as a mathrel object even though it occurs in a non-equation setting is to pre- and post-fix it with (empty) math "atoms", viz., {}.

Note also that it's not necessary to use the align environment as there is really only one "equation" in the example.

\documentclass{article}
\usepackage{array,amsmath}
\newcolumntype{L}{>$l<$}
\begin{document}
\begin{equation*}
    \begin{array}{L@{\quad}c@{{}={}}c}
       some text:            & x^2 & x^2 \\
       more thoughts:        & y^2 & y^2 \\
       really deep thoughts: & z^2 & z^2
    \end{array}
\end{equation*}
\end{document}

enter image description here

share|improve this answer
    
Thanks for your answer. I don't believe I was including the array package and depending on LaTeX's native array support. So for the line \newcolumntype{L}{>$l<$} to work, I guess I will have to use the array package and understand the syntax. –  fg nu Jul 11 '12 at 1:53
    
Okay, so that was pretty amazing. I was wondering why you were telling me all the stuff about mathrel till I added the math atoms and noticed the difference. Double thumbs up to you. ;) –  fg nu Jul 11 '12 at 2:00
1  
@FgNu: The syntax isn't that difficult to master, trust me. Given that the l-type column is automatically in math mode when in an array environment, the >$ prefix serves to end math mode; conversely, the <$ specifier serves to re-enter math mode at the end of the cell's content. As long as you load the array package, you don't actually have to use the \newcolumntype command to set up a column of type L; it suffices (but is less readable, I'd say) to specify >$l<$. –  Mico Jul 11 '12 at 2:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.