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}
Max Flow
  • 354

1 Answers1

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

LaRiFaRi
  • 43,807