TeX - LaTeX Asked on December 10, 2020
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}
newcommandlincomb[3]{% 3args: list of coeffs, vector symb, operation
% begin{tikzpicture}
tikz{
foreach x [count=j] in {#1}{
ifnumj=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}{
ifnumj=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!!
You don't need put the commands in tikz
or tikzpicture
, as the code is just a text, not drawing commands. In fact TeX is indeed trying to typeset these letters, but since it is in the middle of a tikzpicture
, it has been instructed to use the nullfont
, which is an internal font that has no character at all and produces no interword space either. So tikz
or tikzpicture
environment just drop the text as it is not in a node.
documentclass[11pt]{article}
usepackage{tikz,spalign,amsmath}
newcommandlincomb[3]{% 3args: list of coeffs, vector symb, operation
% begin{tikzpicture}
% tikz{
foreach x [count=j] in {#1}{
ifnumj=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.
end{document}
Correct answer by Amita on December 10, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP