4

The following code fails to do what I want:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\tikz{%
\draw (0,0) -- (\textwidth, 0) node[draw, inner sep=5pt,at start, anchor=north] (A)  {\large\textbf{\textsf{Example}}};
}
\end{document}

enter image description here

The problem is that the node's left most rectangular border is not being position at the start of the line. As it is only the middle of the node is being placed at the beginning of the line. Any insights?

azetina
  • 28,884

1 Answers1

4

The north anchor is on the middle top, if you use north west instead, you get the top left corner as anchor. In addition, to get the rectangle directly on top of the line, you have to change the outer sep, which by default is .5\pgflinewidth.

You may also want to add \noindent before \tikz to avoid indentation.

\documentclass{article}
\usepackage{tikz}
\usepackage{showframe} % displays a frame around the text area

\begin{document}
Indented, default \texttt{outer sep}:

\tikz{%
\draw (0,0) -- (\textwidth, 0) node[draw, inner sep=5pt,at start, anchor=north west] (A)  {\large\textbf{\textsf{Example}}};
}

No indent, \texttt{outer sep=0pt}:
-
\noindent\tikz{%
\draw (0,0) -- (\textwidth, 0) node[draw, inner sep=5pt,outer sep=0pt,at start, anchor=north west] (A)  {\large\textbf{\textsf{Example}}};
}
\end{document}

enter image description here

Torbjørn T.
  • 206,688