11

How does one write text such that whatever comes next is placed as if the text had not been written?

Edit: More specifically, I would like to place text in the top-left corner of a tikzpicture by writing the text right before the figure and anchoring the figure as if the text had not been written. Here is an attempt I made that does not work:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\newcommand{\imagetop}[1]{\vtop{\null\hbox{#1}}}

\makebox(0,0){a}
\imagetop{%
    \begin{tikzpicture}
        \draw (0, 0) rectangle (1, 1); 
    \end{tikzpicture}
}
\makebox(0,0){b}
\imagetop{%
    \begin{tikzpicture}
        \draw (0, 0) rectangle (1, 1); 
    \end{tikzpicture}
}

\end{document}
10
  • Which box do you mean?
    – user31729
    May 11, 2015 at 14:29
  • 3
    text here\rlap{more here}and this comes after
    – Sigur
    May 11, 2015 at 14:30
  • Any box. I'll edit the question to avoid confusion.
    – Max Flow
    May 11, 2015 at 14:30
  • 1
    \smash{text} eliminates the vertical footprint of text. May 11, 2015 at 14:32
  • 2
    Please give us an MWE! Why all the guessing? E.g. there is not even a word about vertical size in your OP.
    – LaRiFaRi
    May 11, 2015 at 14:41

1 Answer 1

17

You will have to give us an MWE in order to help you with smashing your tikzpicture. "does not seem to do the job" is no help for us, trying to help you. The typical approaches for smashing would be:

% arara: lualatex

\documentclass{article} 
\usepackage{lua-visual-debug} % leave this away in order to compile with pdfLaTeX

\begin{document}    
% no width  
\makebox[0pt]{Hello}World

\makebox[0pt][l]{Hello}World

% no height and no width
\makebox(0,0){Hello}World

\makebox(0,0)[l]{Hello}World
\end{document}

enter image description here


Edit regarding your posted MWE:

You will have to add a % on the first text line. The new line adds a space if you don't. Just use a left alignment for your box and the word will appear inside the box.

The last point you have to do is to reference the base line to your north side of the square. As I do not know how to reference to the top of a word, I had to apply an yshift here.

% arara: pdflatex

\documentclass{article}
\usepackage{tikz}

\begin{document}    
Hello \makebox[0pt][l]{world}% 
    \begin{tikzpicture}[baseline={([yshift=-\heightof{world}]current bounding box.north)}]
    \draw (0, 0) rectangle (1, 1); 
    \end{tikzpicture}
\end{document}

enter image description here

1
  • @MaxFlow I have added something which addresses your edited question.
    – LaRiFaRi
    May 11, 2015 at 16:11

Not the answer you're looking for? Browse other questions tagged .