0

I'd like to create a float with exact (horizontal & vertical) positioning relative to the point of application, and which has no spatial effect on the surrounding text, either before or after. In other words, a truly free-floating float.

The motivating application is the exact positioning of tikz pictures within lists, and that does not effect the vertical space between items. But it need not be limited to this application. Here is a failed effort to illustrate the point:

\documentclass{article}

\usepackage{tikz}

\newenvironment{floatz}[2]{%
  \begin{minipage}{\textwidth}
    \vspace{#1}\hspace*{#2}
  }{%
  \end{minipage}
}

\begin{document}

\begin{enumerate}
  \item Problem 1
  \item Problem 2
  \item Problem 3
  
  \begin{floatz}{-1in}{2in}
    \begin{tikzpicture}
      \draw (0,0)--(1,0)--(1,1)--(0,1)--(0,0);
    \end{tikzpicture}
  \end{floatz}
  
  \item Problem 4
  \item Problem 5
  \item Problem 6
\end{enumerate}
\end{document}

Unsurprisingly, unwanted vertical space is introduced between items 3 and 4. No less surprising, this is exacerbated if the vertical shift is changed to "positive" 1in. It feels like I need some kind of container that is invisible to the surrounding text, but I'm not aware of such a construct within LaTeX.

3
  • 2
    You can avoid the additional vertical space if you don't start two new paragraphs due to the two empty lines in your code. (however if you want a tikz picture which does not influence the surrounding, why not simply use the overlay option?) Commented May 25 at 21:39
  • 1
    Perhaps tex.stackexchange.com/questions/169808/… Commented May 25 at 21:50
  • I'm not sure I understand what you're aiming to. Can you please show an approximate representation of the desired output?
    – egreg
    Commented May 25 at 21:56

1 Answer 1

5

Exact positioning relative to the source position is more or less explicitly the definition of a non-float. You can use a picture of size (0,0) to take up no space and place it at the start of an item so the offset is relative to a known position.

enter image description here

\documentclass{article}

\usepackage{tikz}

\newcommand\floatz[3]{\begin{picture}(0,0)\put(#1,#2){#3}\end{picture}}


\begin{document}

\begin{enumerate}
  \item Problem 1
  \item Problem 2
  \item
  \floatz{1in}{-.5in}{%
    \begin{tikzpicture}
      \draw (0,0)--(1,0)--(1,1)--(0,1)--(0,0);
    \end{tikzpicture}}%
   Problem 3
  
  \item Problem 4
  \item Problem 5
  \item Problem 6
\end{enumerate}
\end{document}
5
  • 2
    as samcarter has commented if you just want tikz you could use an overlay and dispense with the picture mode, although for positioning general content such as text or an image, not just tikz, you could use picture mode as here and not require tikz. Commented May 25 at 22:38
  • In analyzing your recommendations, I've come to realize that I require the point of application to be at the beginning of a new line that follows the last line of the Problem at issue. This ensures the "intuitive" mounting of a picture at the "end" of the Problem statement, shifting it (usually) to the right and up, alongside the problem that it is associated with (in this case, Problem 3). Of course, this introduces unwanted vertical space as demonstrated by my MWE. I need to somehow eliminate the baselineskip and itemsep that is introduced by my typesetting. Commented May 26 at 19:24
  • @steven_nevets at the end of the item you could use \\\begin{picture...} then you know you have added exactly one \baselineskip extra line so could add a \vspace{-\baselineskip} to compensate Commented May 26 at 20:08
  • Moving the picture to the end of the item and adding your suggested \vspace brings the following item (Problem 4) oh-so close to the desired location - just a smidge short. But the overall picture/put solution is exactly what I was looking for, and I very much appreciate you pointing me to it. On that basis, I'm going to happily accept your solution. Commented May 26 at 20:54
  • David, if I may push my luck, would you mind showing me how to convert your \newcommand{floatz} to a \newenvironment{floatz}? I'm struggling to account for the curly bracket argument of the \put command. Commented May 26 at 23:19

You must log in to answer this question.

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