# Array — dynamic !{decl.} parameter

I use !{=} in array to make compact equation, but on the last line I'd like to have \approx instead of =.

Is it possible ?

\documentclass{standalone}

\usepackage{array,tabularx}

\begin{document}

$\begin{array}{r!{=}l} TS &TU \times\cos\hat{T} \\ &7.5\times\cos\,41.5\\ &5.6\\ % \approx here instead of = \end{array}$

\end{document}

• Note that \cos\,41.5 is wrong. – egreg Dec 15 '15 at 14:32

I'm not sure this is really time-saving.

\documentclass[border=2]{standalone}

\usepackage{array}

\newcommand{\noeq}{\multicolumn{1}{r!{#1}}{}}

\begin{document}

$\begin{array}{r!{=}l} TS &TU \times\cos\hat{T} \\ &7.5\times\cos 41.5 \\ \noeq{\approx} &5.6 \end{array}$

\end{document} I'd do it like this; note that the spacings are the normal ones around the relation symbols.

\documentclass[border=2]{standalone}

\usepackage{array}

\begin{document}

$\begin{array}{r@{}>{{}}l} TS &= TU \times\cos\hat{T} \\ &= 7.5\times\cos 41.5 \\ &\approx 5.6 \end{array}$

\end{document} This might be even more appealing, as it automatically takes care of the space at either side.

\documentclass[border=2]{standalone}

\usepackage{amsmath}

\begin{document}

\begin{aligned} TS &= TU \times\cos\hat{T} \\ &= 7.5\times\cos 41.5 \\ &\approx 5.6 \end{aligned}

\end{document}


For extra flexibility, do consider creating a 3-column array, with the middle column containing the relational operator -- either = or \approx. \documentclass{article}
\usepackage{array} % for "\newcolumntype" macro
\newcolumntype{C}{>{{}}c<{{}}}
\begin{document}

$\setlength\arraycolsep{0pt} \begin{array}{rCl} TS &=&TU \times\cos\hat{T} \\ &=&7.5\times\cos\,41.5\\ &\approx&5.6 \end{array}$
\end{document}

\documentclass{standalone}

\usepackage{array}

\newif\ifUseApprox
\protected\def\Equal{\ifUseApprox\approx\else=\fi}
\def\EqualUseApprox{\global\UseApproxtrue}
\def\EqualUseEqual {\global\UseApproxfalse}

\begin{document}

$\begin{array}{r!{\Equal}l} TS &TU \times\cos\hat{T} \\ &7.5\times\cos\,41.5\\ \EqualUseApprox &5.6\\ % \approx here instead of = \end{array}$

\end{document} \documentclass[varwidth, border=10pt]{standalone}

\usepackage{array, shortvrb}

\newif\ifUseApprox
\protected\def\Equal{\ifUseApprox\approx\else=\fi}
\def\EqualUseApprox{\global\UseApproxtrue}
\def\EqualUseEqual {\global\UseApproxfalse}

\begin{document}
\hsize 6cm

$\begin{array}{r!{\Equal}l} TS &TU \times\cos\hat{T} \\ &7.5\times\cos\,41.5\\ \EqualUseApprox &5.6\\ % \approx here instead of = \end{array}$

I now want to have a line \verb|\approx 7.5\times 0.75|
followed by a line with \verb|= 5.63| !

\EqualUseEqual % reset

$\begin{array}{r!{\Equal}l} TS &TU \times\cos\hat{T} \\ &7.5\times\cos\,41.5\\ \EqualUseApprox &5.6\\ % \approx here instead of = &7.5\times 0.75\\ \EqualUseEqual &5.63\\ % again using = \end{array}$

\end{document} • What if you want to have a line with \approx 7.5\times 0.75 followed by a line with = 5.63? – egreg Dec 15 '15 at 14:38
• @egreg not sure I understand your comment. See addition to my answer. – user4686 Dec 15 '15 at 16:55
• Oh, yes, you have to use \EqualUseEqual. It's better to have an example anyway. – egreg Dec 15 '15 at 17:04
• @egreg \EqualUseEqual was defined in my answer, but yes, not illustrated with an example ;-). – user4686 Dec 15 '15 at 17:29