장 제목 옆에 그림을 어떻게 넣을 수 있나요?

장 제목 옆에 그림을 어떻게 넣을 수 있나요?

이 코드를 사용하여 장 제목 외에 그림을 삽입하려고 합니다.

‎\begin{document}‎
\chapter{for example}
\begin{figure}[h]
\includegraphics[width=20mm]{turing.png}
\end{figure}‎

하지만 그림은 새 줄에 삽입됩니다. 거기에 그림을 삽입할 좌표를 지정할 수 있나요?

답변1

TikZ를 사용할 수 있습니다. 그만큼tikzpagenodes텍스트 영역의 앵커를 사용하여 위치 지정을 쉽게 제어할 수 있습니다.

\documentclass{book}
\usepackage{graphicx}
\usepackage{tikzpagenodes}
\usepackage{lipsum}

\begin{document}‎

\chapter{Test chapter}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=east,inner sep=0pt] at (current page text area.east|-0,3cm) {\includegraphics[height=3cm]{example-image-a}};
\end{tikzpicture}

\lipsum[4]

\end{document}

여기에 이미지 설명을 입력하세요

답변2

명령 에 그래픽을 지정하는 경우 chaptertoc 파일을 작성할 때 해석되지 않도록 해당 명령을 보호해야 합니다. 또는 다른 제목을 지정하십시오.

\documentclass[12pt, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[demo]{graphicx}

\begin{document}
\tableofcontents

\chapter{looks odd in TOC \protect\includegraphics[width=20mm]{test.png}}
\chapter[does not look so odd in TOC (because the graphic is missing)]%
        {does not look so odd in TOC \includegraphics[width=20mm]{test.png}}

\end{document}

답변3

-command의 인수 에 그래픽을 포함하려고 한다는 불만이 접수되었으므로 \chapter다음과 같은 방법이 도움이 되었습니다.

이것은 무엇보다도 해킹입니다. 하지만 할 수 있는 한 가지는 그래픽을 다음 줄에 포함하고 음수로 위로 이동하는 것입니다 \vspace. 어떤 단위를 사용해도 되지만, \baselineskip수직 공간의 높이에 대해 mm나 pt와 같은 절대적인 단위보다는 상황에 맞게 정의된 것과 같은 것을 사용하는 것이 가장 좋다고 생각합니다. \vspace장의 본문이 캡션에 눌리지 않도록 나중에 긍정적인 부분을 포함시키십시오 .

모든 챕터에 사용할 그래픽을 원할 경우 다음과 같이 그림을 참조하는 두 번째 인수가 필요하다는 점을 제외하고는 이 모든 것을 챕터처럼 동작하는 매크로로 압축할 수 있습니다.

    \documentclass[final]{book}
\usepackage{graphicx, ifthen}

    \newcommand{\mychapter}[3][\empty]{%
        \ifthenelse{\equal{#1}{\empty}}% check whether optional parameter is empty
                         {\chapter[#2]{#2}}% 
                         {\chapter[#1]{#2}}% 
        {\Huge %
           \vspace{-2.2\baselineskip} % move up
           \hfill % move graphic right
           \includegraphics[height=10mm]{#3} % include graphic
           \vspace{\baselineskip} % move down before body starts
        }% delimit scope of \Huge
    }

\begin{document}‎
\tableofcontents

\mychapter[toc title]{A chapter}{Logo-univie}%different title in TOC and heading

\mychapter{Another chapter}{Logo-univie}%same title everywhere

Some text
\end{document}

참고: 의 선택적 인수를 유지하도록 편집되었습니다 \chapter.

관련 정보