如何用图片填充页面

如何用图片填充页面

我想用图片填满一页(尽可能保持图片的纵横比)。

我希望图片填满整个页面,超出边距。(我希望在包含文本的页面上,边距一般不为零。)页面只是一个屏幕,而不是打印纸。

这是我的最佳尝试;存在几个问题:

  • 图片顶部被剪裁
  • 底部有一小块空白
  • 整个内容出现在第 2 页,第一页被跳过
    \documentclass{article}
    \usepackage{graphicx}
    \usepackage[paperwidth=1920bp,paperheight=1080bp,margin=60bp]{geometry}

    \newcommand\fillpic[1]{%
      \begin{minipage}[t][\textheight][c]{\textwidth}
         \vss%
         \null\hfill%
         \includegraphics*[keepaspectratio=true,%
         width=\linewidth,height=\paperheight]{#1}%
         \hfill\null%
         \vss%
       \end{minipage}}

    \begin{document}
    \fillpic{example-image-a}%
    \end{document}

答案1

我很乐意删除它,但你在寻找类似的东西吗?

\documentclass{article}
\usepackage{tikz}
\usepackage[paperwidth=1920bp,paperheight=1080bp,margin=60bp]{geometry}

\newcommand\fillpic[1]{%
  \setbox0\hbox{\includegraphics*[keepaspectratio=true,]{#1}}%
  % ^ this measures the dimensions of the graphics
  \begin{tikzpicture}[overlay,%<-allow the picture to go over the page borders
   remember picture%<-access to page anchors like page.center
   ]
  \pgfmathsetmacro{\myscale}{min(\the\paperwidth/\the\wd0,\the\paperheight/\the\ht0)}%   
  % ^ compute the scale factor as the minimum of ... to make sure the graphics does not overshoot
   \node at (current page.center){\includegraphics*[keepaspectratio=true,%
    scale=\myscale]{#1}};% <- add the graphics with the appropriate scale
    % at the center of the page.
  \end{tikzpicture}}

\begin{document}
\fillpic{example-image-a}%
\clearpage
\fillpic{example-image-16x9}%
\end{document}

答案2

您可以使用 来将内容放置在当前页面的BackG轮(或Fore轮)(使用 的-version )中G*\AddToShipoutPictureBGeso-pic

在此处输入图片描述

\documentclass{article}

\usepackage{graphicx,eso-pic}
\usepackage[paperwidth=1920bp,paperheight=1080bp,margin=60bp]{geometry}

\newcommand{\fillpic}[2][]{%
  \mbox{}\ignorespaces% Put something (\mbox{}) on the page
  \AddToShipoutPictureBG*{% Place image in the BackGround of _this_ page
    \AtPageCenter{% Place the image at the centre of the page
      \makebox[0pt]{% Set the image inside a 0pt-width box that is horizontally centred (by default)
        \raisebox{-.5\height}{% Move the image vertically centred on the page
          \includegraphics[
            keepaspectratio=true,
            width=\paperwidth,
            height=\paperheight,
            #1
          ]{#2}%
        }% \raisebox
      }% \makebox
    }% \AtPageCenter
  }% \AddToShipoutPictureBG*
}

\begin{document}

\fillpic{example-image-a}

\end{document}

我已向 添加了可选参数\fillpic[<img parameters>][<image>}

相关内容