1

i have code but caption does not in center and not below of image

MWE:

\documentclass{article}

\usepackage{caption}  

\usepackage{tikzpagenodes}

\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}[remember picture,overlay,shift={(current page.north west)}]
\node[anchor=north west,xshift=3cm,yshift=-4cm]{\includegraphics[width=3cm]{example-image-a}};
\end{tikzpicture}
\caption*{ABC DEF}
\end{center}
\end{figure}
\end{document}

Please help that put caption below (0.4cm) and center of image

Thanks enter image description here

4
  • 2
    You've shifted the image, and a caption is centred on the line.
    – Bernard
    Jul 16 '19 at 9:32
  • @Bernard wow, and how can i shift caption of image?
    – latexforti
    Jul 16 '19 at 9:39
  • 1
    If you always use the \caption*{} instead of \caption{}, you can add TiKz label to your graphic node.
    – user31034
    Jul 16 '19 at 9:50
  • 1
    This can be done with the caption package more or less playing with parameters by trial and error? However, does your real figure have so much white space, or are you trying to have a special layout for a normal image?
    – Bernard
    Jul 16 '19 at 9:58
1

like this:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node (n1)[anchor=north west, inner sep=0pt,
           xshift=3cm, yshift=-4cm] at (current page.north west) {\includegraphics[width=3cm]{example-image-a}};
\node [below=4mm] at (n1.south) {ABC DEF};
\end{tikzpicture}
\end{document}
5
  • That's exactly what I meant.
    – user31034
    Jul 16 '19 at 10:01
  • 1
    @ferahfeza, oh now I see your comment ... it looks like both of them were loaded almost simultaneously.
    – Zarko
    Jul 16 '19 at 11:03
  • Ok, no problem. I wrote that comment to OP. I know the important thing here is to help someone.
    – user31034
    Jul 16 '19 at 11:07
  • Yeah. Please note that the 3cm and -4cm shifts are not relative to the top-left corner of the page, because you don't set inner sep=0 in the node options. Try the provided code with xshift=0cm,yshift=0cm and you should see what I mean.
    – frougon
    Jul 16 '19 at 12:46
  • @frougon, i add inner sep=0pt. image is now closer to text border (assuming, that with shift is image moved to this border)
    – Zarko
    Jul 16 '19 at 13:13
1

Because of the use of the overlay and shift options, your tikzpicture is essentially disconnected from the normal text flow. Your \caption* command isn't connected to the tikzpicture, it simply places a caption where it is, inside an essentially empty figure. Therefore, I suggest to completely omit the figure and center environments here, since they serve no purpose apart from holding the caption, which is not typeset in the desired place this way.

First method

If you want a figure-like caption below your tikzpicture, you can use \captionof from the caption package inside a node created with text width=3cm, for instance:

\documentclass{article}
\usepackage{caption}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
\node[inner sep=0, anchor=north west, text width=3cm, shift={(3cm,-4cm)}]
  at (current page.north west)
  {\includegraphics[width=3cm]{example-image-a}%
   \captionof{figure}{ABC DEF}};
\end{tikzpicture}

\end{document}

enter image description here

I used a placement technique (\node[...] at (...) {...}) that I find easier to understand than the one used in your example. Also:

  • I added inner sep=0 as part of the node options, otherwise the offsets you are specifying are not interpreted against the top-left corner of the page (try with xshift=0cm and yshift=0cm, or equivalently with shift={(0cm,0cm)}).

  • I replaced \usepackage{tikzpagenodes} with \usepackage{tikz}. You might believe that tikzpagenodes was needed in your example because it loads tikz as a side effect, and you effectively needed tikz without loading it explicitly; but you don't use anything from tikzpagenodes: the current page node is part of tikz, it doesn't require tikzpagenodes in any way, contrary to other nodes you don't use: current page text area, current page marginpar area, current page header area and current page footer area. Loading tikzpagenodes instead of tikz here is just a waste of time and memory.

Second method

Another way is to prepare the caption text by hand using an option that makes the node a multiline one, such as align=center (see Text Parameters: Alignment and Width for Multi-Line Text in the TikZ & PGF Manual, page 229 for version 3.1.3 or, for instance, this answer):

\documentclass{article}
\usepackage{caption}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
\node[inner sep=0, anchor=north west, align=center, shift={(3cm,-4cm)}]
  at (current page.north west)
  {\includegraphics[width=3cm]{example-image-a}\\
   \textbf{My:} hand-made caption};
\end{tikzpicture}

\end{document}

enter image description here

Third method

A variant of the second method consists in placing the caption in a separate node: this is what Zarko did in his answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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