標題旁邊邊距中的圖像

標題旁邊邊距中的圖像

我想在標題旁邊的邊距中添加圖像。圖像的底部應與標題基線對齊。在我的 MWE(見下文)中,圖像的頂部隨標題頂部進行調整。

如何在基線處調整影像?

您有其他改進建議嗎?例如,使用marginnotein有意義嗎ihead

微量元素:

\documentclass{scrreprt}

\usepackage{blindtext, graphicx, marginnote}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\ihead{%
    \marginnote{%
            \includegraphics[width=\marginparwidth]{example-image-a}%
        }
}

\begin{document}
\Blinddocument
\end{document}

答案1

我不會使用marginnote,但只會使用scrlayer-scrpage

\documentclass{scrreprt}

\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\rohead{\headmark\makebox[0pt][l]{\hskip\marginparsep\includegraphics[width=\marginparwidth]{example-image-a}}}
\lehead{\makebox[0pt][r]{\includegraphics[width=\marginparwidth]{example-image-a}\hskip\marginparsep}\headmark}

\begin{document}
\Blinddocument
\end{document}

在此輸入影像描述

您也可以將自己的圖層新增到頁面樣式scrheadings,如果您希望圖像也出現在一般頁面上plain.scrheadings

\documentclass{scrreprt}

\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\DeclareNewLayer[background,
  head,
  addhoffset=\ifodd\value{page}\textwidth+\marginparsep\else-\marginparwidth-\marginparsep\fi,
  width=\marginparwidth,% optional reduce layer width
  contents={\includegraphics[width=\marginparwidth]{example-image-a}}]{image}

\AddLayersToPageStyle{scrheadings}{image}
%\AddLayersToPageStyle{plain.scrheadings}{image}

\begin{document}
\Blinddocument
\end{document}

結果是相同的,但不需要將 of 拆分\ihead\lehead\rohead。您只需啟動單一註解行即可啟動普通頁面的圖像。

順便說一句:我建議將圖像一次放入一個框中,並在每一頁上使用該框:

\documentclass{scrreprt}

\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\DeclareNewLayer[background,
  head,
  addhoffset=\ifodd\value{page}\textwidth+\marginparsep\else-\wd\headimagebox-\marginparsep\fi,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image}

\AddLayersToPageStyle{scrheadings}{image}
\AddLayersToPageStyle{plain.scrheadings}{image}% used on chapter start page

\begin{document}
\Blinddocument
\end{document}

如果程式碼應在單面模式下始終將徽標放置在右側:

\documentclass{scrreprt}
%\documentclass[twoside]{scrreprt}

\usepackage{mwe,graphicx}
\usepackage{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\makeatletter
\DeclareNewLayer[background,
  head,
  addhoffset=\ifcase\if@twoside \ifodd\value{page} 0 \else 1 \fi\else 0 \fi\textwidth+\marginparsep\else-\wd\headimagebox-\marginparsep\fi,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image}
\makeatother

\AddLayersToPageStyle{scrheadings}{image}
\AddLayersToPageStyle{plain.scrheadings}{image}% used on chapter start page

\begin{document}
\Blinddocument
\end{document}

但在這種情況下,為左頁和右頁使用不同的圖層可能會更容易:

\documentclass{scrreprt}
%\documentclass[twoside]{scrreprt}

\usepackage{mwe,graphicx}
\usepackage{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\DeclareNewLayer[background,
  oddpage,% for right pages in double-side mode or all pages in single-side mode
  head,
  addhoffset=\textwidth+\marginparsep,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image.odd}
\DeclareNewLayer[background,
  evenpage,% for left pages in double-side mode
  head,
  addhoffset=-\wd\headimagebox-\marginparsep,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image.even}

\AddLayersToPageStyle{scrheadings}{image.odd,image.even}
\AddLayersToPageStyle{plain.scrheadings}{image.odd,image.even}% used on chapter start page

\begin{document}
\Blinddocument
\end{document}

相關內容