latex fit image in page auto adjusting width code example

Example 1: latex image textwidth

\documentclass{article}
 \usepackage{graphicx}
 \begin{document}
   \includegraphics[width=0.5\textwidth]{file}
 \end{document}

Example 2: how to fit a whole picture on page in latex

\newlength{\textundbildtextheight}
 
\newcommand{\textundbild}[2]{
\settototalheight\textundbildtextheight{\vbox{#1}}
#1
\vfill
\begin{center}
\includegraphics[width=\textwidth,keepaspectratio=true,height=\textheight-\the\textundbildtextheight]{#2}
\end{center}
\vfill
}

Tags:

Misc Example