如何修改TikZ代码实现LaTeX公式的直角箭头注释?
Got it! Let's adjust your existing TikZ code to swap those curved arrows for clean right-angle ones. I'll base this on a typical curved-arrow setup you might have used, so you can map it directly to your own code:
Modified Code with Right-Angle Arrows
\documentclass{article} \usepackage{amsmath} \usepackage{tikz} \usetikzlibrary{positioning, tikzmark} % Keep your existing libraries \begin{document} \[ % Example formula with tikzmarks (adjust to match your original structure) \sum_{i=1}^{\tikzmark{upper-limit}n} x_i = \underbrace{x_1 + x_2 + \dots + x_n}_{\tikzmark{brace}n \text{ terms}} \] \begin{tikzpicture}[overlay, remember picture, thick, ->] % Right-angle arrow for upper limit (first vertical, then horizontal) \node[above=15pt of pic cs:upper-limit, anchor=south] (limit-note) {*Number of elements to sum*}; \draw (limit-note.south) |- (pic cs:upper-limit); % Right-angle arrow for underbrace (first horizontal, then vertical) \node[below=15pt of pic cs:brace, anchor=north] (brace-note) {*Expanded sum of all terms*}; \draw (brace-note.north) -| (pic cs:brace); \end{tikzpicture} \end{document}
Key Changes to Your Original Code
- Replace curved path commands (like
bend left,curve to, or.. controls ..) with TikZ's built-in right-angle operators:|-: Draws a vertical segment first, then horizontal (perfect for arrows coming from above/below and turning toward the formula)-|: Draws a horizontal segment first, then vertical (ideal for arrows coming from left/right and turning toward the formula)
- Keep your existing
tikzmarkor node positioning logic intact—you only need to update the arrow path itself. - If you need precise control over the corner of the right angle, you can manually define the turning point instead of using
|-/-|, e.g.:\draw (note.south) -- ++(0,-8pt) -- (pic cs:target); % Manual vertical then horizontal
This maintains the simplicity of your original code while giving you the sharp right-angle arrows you need.
内容的提问来源于stack exchange,提问作者Tianwei Yue
相关产品推荐
相关产品推荐

