如何在LaTeX中使用背景圖片?

如何在LaTeX中使用背景圖片?

我正在產生一份需要使用背景圖像的報告。但我發現影像總是開始在左側留下一些邊距空間。

\documentclass{article}
\usepackage{wallpaper}
\usepackage{mdframed}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\begin{document}
 Some content
\ThisLRCornerWallPaper{1.0}{image.jpg}
\end{document} 

如何使用覆蓋整個頁面的背景影像?

答案1

您可以透過多種方式做到這一點。我將展示另外三種方法。

tikz

\documentclass{article}
\usepackage{tikz}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\begin{document}
 Some content
\tikz[remember picture,overlay] \node[opacity=0.3,inner sep=0pt] at (current page.center){\includegraphics[width=\paperwidth,height=\paperheight]{example-image}};
\clearpage
text
\end{document}

eso-pic

\documentclass{article}
\usepackage{eso-pic,graphicx}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\begin{document}
 Some content
\AddToShipoutPictureBG*{\includegraphics[width=\paperwidth,height=\paperheight]{example-image}};
\clearpage
text
\end{document}

\AddToShipoutPictureBG(而不是 \AddToShipoutPictureBG*)將背景放在所有頁面中。

background包裝:

\documentclass{article}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\usepackage[pages=some]{background}

\backgroundsetup{
scale=1,
color=black,
opacity=0.4,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{example-image}
  }%
}
\begin{document}
 \BgThispage
 Some content
 \clearpage
 text
\end{document}

在此輸入影像描述

答案2

這是使用(相對)新巨集的解決方案\AddToHook

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}

\AddToHook{shipout/background}{%
    \put (0in,-\paperheight){\includegraphics[width=\paperwidth,height=\paperheight]{mybg.pdf}}%
}

\begin{document}
\lipsum[1-5]
\end{document}

(該background包現在會發出警告,因為它使用了已棄用的巨集。)

答案3

我發現我花了一段時間尋找如何跳過特定頁面的背景圖像。我發現最好的方法是:

\usepackage[pages=some]{background}
\backgroundsetup{
scale=0.1,
color=black,
opacity=0.1,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{Picture.png}
  }%
}

----- Page Wanting to Omit -----

Blah Blah Blah

\NoBgThispage % <------- Skips for current page
\BgThispage % <------- Starts bg again for next page

Blah Blah Blah

希望這對某人有幫助。

相關內容