1

I'm using a loop to write several labels for line intersections, but perhaps for reasons of scale or something the labels are a bit too far away from the intersections. I can't fix each manually since I'm using a loop, and adding a fixed correction means errors propagate through the loop and the last labels are completely off.

\documentclass[11pt,border=5pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw (0,1) -- (2,1);
\draw (1,0) -- (1,2);

\node [anchor=north west] at (1,1) {Some text};
\node [anchor=north east] at (1.13,1.13) {Some text}; % Manual fix applied

\end{tikzpicture}
\end{document}

Here's my (extreme) MWE, and my actual application.

MWE example Example image

I'm wondering if there's a way to move the anchor so that it's slightly within the text bounding box or something.

2
  • Sorry, but: Unknown function 'calculation' (in 'calculation involving 1'). ... Would you mind post a compilable minimal (non-)working example? Dec 2, 2021 at 15:49
  • @JasperHabicht Agree wasn't a well-formatted question. Improved now.
    – thosphor
    Dec 2, 2021 at 16:53

1 Answer 1

2

You can use inner sep with even negative values to shift the text of the node while keeping the anchor. Alternatively, use outer sep which would keep the padding to the text, in case you use borders.

Use inner xsep or inner ysep (or outer xsep or outer ysep) if you only want to apply this shift horizontally or vertically.

I am unsure if this can be used in your case, though.

\documentclass[11pt,border=5pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw (0,1) -- (2,1);
\draw (1,0) -- (1,2);

\node [anchor=south east, outer xsep=-10pt, draw=red] at (1,1) {Some text};

\node [anchor=north west, inner sep=-5pt] at (1,1) {Some text};

\node [anchor=north east, inner sep=0pt] at (1,1) {Some text}; % Now (almost) overlapping with the following node
\node [anchor=north east] at (1.13,1.13) {Some text}; % Manual fix applied
    
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.