文字背後的圖像與花式

文字背後的圖像與花式

我想在我的乳膠文檔中的頁碼後面有一個圖像,並嘗試像這樣寫

\fancyhead[CE,CO]{\textcolor{white}{\thepage}}
\chead{\includegraphics[width=1cm]{img.eps}}

問題是:當我首先得到帶有頁碼的行,然後是圖像時,我只能得到圖像,如果我有相反的方法,那麼我只能得到數字。怎麼樣才能讓圖片前面有數字呢?我應該使用背景圖片嗎?

答案1

這是一種方法:

\documentclass{article}
\usepackage{fancyhdr,stackengine,xcolor,graphicx}
\fancypagestyle{mystyle}{
\chead{\stackinset{c}{}{c}{}{\textcolor{red}{\thepage}}{%
  \includegraphics[width=1cm]{example-image}}}
}
\pagestyle{mystyle}
\begin{document}
My text
\end{document}

在此輸入影像描述

答案2

您可以按照您希望分層的順序設定內容。

考慮到上述情況,我們可以在Left 標頭中設定圖像,然後設定Centred 標頭:

在此輸入影像描述

\documentclass{article}

\usepackage{graphicx,fancyhdr,xcolor,lipsum}

\fancyhead[C]{\textcolor{white}{\thepage}}
\fancyhead[L]{\makebox[\textwidth]{\includegraphics[height=.7\baselineskip]{example-image}}}
\pagestyle{fancy}

\begin{document}

\lipsum[1-10]

\end{document}

eft標頭設定在自然居中的L寬度框中。\textwidth可能需要調整影像的位置。

如果您想要的只是黑色背景上的白色頁碼,您可以使用

\fancyhead[C]{\raisebox{0pt}[0pt][0pt]{\colorbox{black}{\textcolor{white}{\thepage}}}}

它使用以下命令設定頁碼\colorbox

在此輸入影像描述

相關內容