TeX - LaTeX Asked on April 6, 2021
Consider the following MWE:
documentclass[letterpaper]{article}
usepackage[dvipsnames]{xcolor}
usepackage{tikz}
usepackage{lipsum}
usetikzlibrary{tikzmark,calc}
usepackage{amsmath}
begin{document}
lipsum[1-2]
[
tikzmarknode{base}{2}^{tikzmarknode{exp}{3}}=2cdot 2cdot 2
]
begin{tikzpicture}[remember picture,overlay]
draw[stealth-,OrangeRed] (base)-- ($ (base.south west) + (-2ex,0) $) node[inner sep=1pt,left,font=footnotesizesffamily,OrangeRed] {base};
draw[stealth-,Cerulean] (exp) -- ($ (base.north east) + (2ex,2ex) $) node[inner sep=0pt, above right,font=footnotesizesffamily,Cerulean] {exponent};
end{tikzpicture}
lipsum[1]
end{document}
How can I ensure proper spacing above and below the diagram? That is, I would like the overly to respect the math spacing above and below and not bleed out into the text above.
Also if there are possible or better ways of labeling the diagram I would appreciate it.
Measure the distances and add them.
documentclass[letterpaper]{article}
usepackage[dvipsnames]{xcolor}
usepackage{tikz}
usepackage{lipsum}
usetikzlibrary{tikzmark,calc}
usepackage{amsmath}
begin{document}
lipsum[1-2]
[
tikzmarknode{base}{2}^{tikzmarknode{exp}{3}}=2cdot 2cdot 2
begin{tikzpicture}[remember picture,baseline={(aux.base)}]
begin{scope}[overlay]
draw[stealth-,OrangeRed] (base)-- ($ (base.south west) + (-2ex,0) $)
node[inner sep=1pt,left,font=footnotesizesffamily,OrangeRed] (aux1){base};
draw[stealth-,Cerulean] (exp) -- ($ (base.north east) + (2ex,2ex) $)
node[inner sep=0pt, above right,font=footnotesizesffamily,Cerulean]
(aux2){exponent};
end{scope}
path node(aux){vphantom{.}}
let p1=($(aux1.north)-(aux.base)$),
p2=($(aux1.south)-(aux.base)$),
p3=($(aux2.north)-(aux.base)$),
p4=($(aux2.south)-(aux.base)$) in
foreach z in {1,...,4} {(0,yz)};
end{tikzpicture}
]
lipsum[1]
end{document}
One can also use fit
to shorten the code a bit. (This even rhymes.;-)
documentclass[letterpaper]{article}
usepackage[dvipsnames]{xcolor}
usepackage{tikz}
usepackage{lipsum}
usetikzlibrary{tikzmark,calc,fit}
usepackage{amsmath}
begin{document}
lipsum[1-2]
[
tikzmarknode{base}{2}^{tikzmarknode{exp}{3}}=2cdot 2cdot 2
begin{tikzpicture}[remember picture,baseline={(aux.base)}]
begin{scope}[overlay]
draw[stealth-,OrangeRed] (base)-- ($ (base.south west) + (-2ex,0) $)
node[inner sep=1pt,left,font=footnotesizesffamily,OrangeRed] (aux1){base};
draw[stealth-,Cerulean] (exp) -- ($ (base.north east) + (2ex,2ex) $)
node[inner sep=0pt, above right,font=footnotesizesffamily,Cerulean]
(aux2){exponent};
node[fit=(aux1)(aux2),inner sep=0pt](auxf){};
end{scope}
path node(aux){vphantom{.}}
let p1=($(auxf.north)-(aux.base)$),
p2=($(auxf.south)-(aux.base)$) in
(0,y1) (0,y2);
end{tikzpicture}
]
lipsum[1]
end{document}
Answered by user232027 on April 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP