Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
Correct me if I am wrong but the north west, if zoomed is the middle of the line drawn not exactly flush with the line and the rectangle right? –  azetina Mar 5 '13 at 19:11
    
@azetina Correct, it is because of the outer sep, I was just about to add something about that. (If I understand you correctly, that is.) –  Torbjørn T. Mar 5 '13 at 19:14
    
Yeah could you add something about that? I guess setting outer sep to zero does the trick right? –  azetina Mar 5 '13 at 19:22
    
@azetina Done, and yes. –  Torbjørn T. Mar 5 '13 at 19:24
    
@azetina A related question which exhibits this is: Properly aligning drawn lines between the corners of 2 rectangular nodes in TikZ?. By the way, a short-cut for anchor=north west is below left. –  Qrrbrbirlbel Mar 5 '13 at 19:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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