0

I'm trying to align an image (3200x2368) to the top of the page. It is not aligned and I don't know what I can try more than this. Anything I tried doesn't make the picture to align on top and on the left side without any margins. Why is that and how can it be fixed?

\documentclass{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{graphicx, pgffor}
\usepackage[export]{adjustbox}
\pagenumbering{gobble}
\begin{document}
\pagestyle{empty}%
\noindent
\begin{figure}[t]
  \vspace{0pt}
  \includegraphics[width=7in,valign=t]{test.jpg}
  \caption{Test Caption}
\end{figure}
\end{document}

This is the test image

image

Ant this is how the document looks like

document

1
  • a4paper, total={6in, 8in} ?? what size do you want the page to be, A4 or 6" by 8" ? either way you specfy the image as 7" wide starting at the left margin. Commented Apr 11, 2023 at 19:28

2 Answers 2

0

You can use the tikz package to align the top left corner of the image to the top left corner of the page.

The image is wider than the width of the page (597.5pt). Using width=\paperwidth,keepaspectratio will make it fit.

To accommodate the option bellow the image, add a suitable vertical space \vspace{<space>}.

a

\documentclass{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{graphicx, pgffor}
\usepackage[export]{adjustbox}
\pagenumbering{gobble}

\usepackage{tikz}% added<<<<<<<<<<<<

\begin{document}    
    
\pagestyle{empty}%
\noindent
\begin{figure}      
    \begin{tikzpicture}[remember picture, overlay]
        \node[anchor=north west, align=left, inner sep=0] at (current page.north west){\includegraphics[width=\paperwidth,keepaspectratio]{test.jpg}};      
    \end{tikzpicture}
    \vspace{330pt}% move the caption down <<<<
    \caption{Test Caption}
\end{figure}    
\end{document}
0

This simply overlaps the margins while maintaining the distance to the caption. Without adding some text, the figure becomes a [p] float and is centered on the page instead of at the top. Be warned that graphicx uses some of registers 0-9. but I forget which ones.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}% not used
\usepackage{ifoddpage}
\usepackage{lipsum}% MWE only
\begin{document}
\begin{figure}[t]
  \setlength{\dimen9}{\dimexpr 1in+\topmargin+\headheight+\headsep}% vertical offset
  \checkoddpage
  \ifoddpage
    \setlength{\dimen8}{\dimexpr 1in+\oddsidemargin}% left margin
  \else
    \setlength{\dimen8}{\dimexpr 1in+\evensidemargin}%
  \fi
  \setlength{\dimen7}{\dimexpr \paperwidth-\textwidth-\dimen8}% right margin
  \vskip-\dimen9\hskip-\dimen8
  \includegraphics[width=\paperwidth, keepaspectratio]{example-image}%
  \hskip-\dimen7
  \caption{Test Caption}
\end{figure}
\lipsum[1-4]% wihtout the text, it bcomes a [p] float
\end{document}

You must log in to answer this question.

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