I wrote a macro to print linear combinations and related things using TikZ (pgffor
really, but I need TikZ for other things in a big document). Here's a MWE:
\documentclass[11pt]{article}
\usepackage{tikz,spalign,xspace,amsmath}
\newcommand\lincomb[3]{% 3args: list of coeffs, vector symb, operation
% \begin{tikzpicture}
\tikz{
\foreach \x [count=\j] in {#1}{
\ifnum\j=1
$\x{#2}_{\j}$
\else
${#3}\x{#2}_{\j}$
\fi
}\xspace
% \end{tikzpicture}
}
}
\begin{document}
\begin{equation}
\spalignmat{0.7;0.5;0.1}={\lincomb{0.7,0.5,0.1}{\mathbf{e}}{+}}\quad
\;\text{and}\:
\spalignmat{0.1;0.5;0.7}=\lincomb{0.1,0.5,0.7}{\mathbf{e}}{+}
\end{equation}
$\lincomb{a,b,c}{f}{-}$ and then some text.
\begin{tikzpicture}
\foreach \x [count=\j] in {a,b,c,d}{
\ifnum\j=1
$\x f_{\j}$
\else
$+ \x f_{\j}$
\fi
}
\end{tikzpicture}\ and then some text
\end{document}
The output is at the end. What I want is to have proper spacing between two of these. As you can see, I even tried using the code as a standalone piece of text, but got the same result; I also tried using the tikzpicture
environment, but nothing changes. After seraching I've seen many questions asking to remove space after a tikzpicture
, but I want to add it. As you can see also, xspace
doesn't work here either. Thanks in advance!!