2

been trying to align caption text within a tikz node overlayed on an image

tried multiple ways, but either it doesn't align center or if I use \centering it removes line breaks(which I don't wont

Can someone point in me in the right direction....

\documentclass[a4paper,10pt,twoside]{book}
\usepackage[paperwidth=210mm, paperheight=297mm, top=25.4mm,bottom=25.4mm,left=25.4mm,right=25.4mm]{geometry}
\usepackage{graphicx}
\usepackage{hvfloat}
\usepackage[export]{adjustbox}
\usepackage{caption}
\usepackage{tikz}
\usepackage[noinfo, width=216truemm, height=303truemm, cam, pdftex, center]{crop}




%get the image width
\makeatletter
\def\maxwidth{%
  \ifdim\Gin@nat@width>\textwidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother


\begin{document}

\newlength{\imagewidth}

\settowidth{\imagewidth}{\includegraphics{example-image}}

%portrait image full page size
\begin{figure}
\settowidth{\imagewidth}{\includegraphics{example-image}}

\begin{tikzpicture}[remember picture,overlay]
   \node [xshift=0mm, yshift=0mm, anchor=center] at (current page.center)
   {\includegraphics[max width=\dimexpr\paperwidth+6mm\relax, height=\dimexpr\paperheight+6mm\relax, keepaspectratio=true]{example-image}};
\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]%
\node [fill=white, anchor=south, text=black, opacity=0.7, text opacity=1, inner xsep=3mm,inner ysep=3mm, xshift=0mm, yshift=0mm, align=center, rounded corners=6mm, text width=0.75\linewidth] at (current page.south) { \begin{center} \caption{
\textbf{\LARGE{King Henry VIII} \\ \\ \normalsize\textit{Tudor King of England, Ireland and Scotland}\label{fig}} \\ \\ Prone to beheading his wives  \\ \\ \textbf{``SERIOUSLY TERRIBLE DUDE"} \\ \\ \textit{``Imagine being related to this guy"}\\ No thank you! and people actually aspire to be one these people? go figure     
} 
\end{center}};
\end{tikzpicture}

\end{figure}



\end{document}

6
  • it would be easier to understand the question and test answers if you used example-image as the image as that is available for tests. Meanwhile note size commands do not take an argument so \LARGE{... , ` \normalsize{..` shouldn not have the {} Commented Jul 14, 2021 at 7:26
  • @DavidCarlisle - ok thanks for the pointer, BTW I don't know how to include example-image as fairly new to LateX
    – Jonas
    Commented Jul 14, 2021 at 7:31
  • 2
    just use \includegraphics[width=whatever,,....]{example-image} and if you have anything like a normal tex installation it will just work. Commented Jul 14, 2021 at 7:32
  • Not sure if you can use a caption inside a node...
    – Rmano
    Commented Jul 14, 2021 at 7:36
  • @DavidCarlisle - amended the code as requested
    – Jonas
    Commented Jul 14, 2021 at 7:39

1 Answer 1

3

something like this, I guess.

enter image description here

avoid use of \\ outside alignments, size commands don't take arguments and use '' not " to close a quote, and use caption package (as you are loading it anyway) to format the caption). Otherwise as you had it.

\documentclass[a4paper,10pt,twoside]{book}
\usepackage[paperwidth=210mm, paperheight=297mm, top=25.4mm,bottom=25.4mm,left=25.4mm,right=25.4mm]{geometry}
\usepackage{graphicx}
\usepackage{hvfloat}
\usepackage[export]{adjustbox}
\usepackage{caption}
\usepackage{tikz}
\usepackage[noinfo, width=216truemm, height=303truemm, cam, pdftex, center]{crop}




%get the image width
\makeatletter
\def\maxwidth{%
  \ifdim\Gin@nat@width>\textwidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother


\begin{document}

\newlength{\imagewidth}

%?\settowidth{\imagewidth}{\includegraphics{example-image}}

%portrait image full page size
\begin{figure}
\settowidth{\imagewidth}{\includegraphics{example-image}}
\captionsetup{justification=centering}

\begin{tikzpicture}[remember picture,overlay]
   \node [xshift=0mm, yshift=0mm, anchor=center] at (current page.center)
   {\includegraphics[max width=\dimexpr\paperwidth+6mm\relax, height=\dimexpr\paperheight+6mm\relax, keepaspectratio=true]{example-image}};
\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]%
\node [fill=white, anchor=south, text=black, opacity=0.7, text opacity=1, inner xsep=3mm,inner ysep=3mm, xshift=0mm, yshift=0mm, align=center, rounded corners=6mm, text width=0.75\linewidth] at (current page.south) {
\caption
{
\textbf{\LARGE King Henry VIII}\\
\textit{Tudor King of England, Ireland and Scotland}\label{fig}}

Prone to beheading his wives

\textbf{``SERIOUSLY TERRIBLE DUDE''}

\textit{``Imagine being related to this guy''}

No thank you! and people actually aspire to be one these people? go figure     
};
\end{tikzpicture}

\end{figure}



\end{document}

You must log in to answer this question.

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