이미지에 대한 사용자 정의 기능 생성

이미지에 대한 사용자 정의 기능 생성

오늘 LaTeX를 몇 가지 살펴보았는데 이미지를 표시하는 사용자 정의 기능을 얻는 방법이 궁금합니다.

제가 원했던 것은 각 챕터 이미지에 대해 올바른 디렉토리로 연결되고 사진에 캡션을 추가할 수 있는 사용자 정의 기능을 갖는 것이었습니다.

텍스트를 이미지 중앙에 맞추려고 합니다(이미지 캡션에 대한 모범 사례가 될 수 있을까요?).

하지만 현재 기능은 다음과 같습니다.

\newcommand{\qweq}[3]{
\begin{figure}
\centering
\includegraphics[width=9cm]{/images/task#1/#2}
\caption{
\emph{
\small{
#3
}
}
}

텍스트를 중앙에 배치하는 방법을 잘 모르겠습니다. 현재 텍스트 본문과 크게 차별화되도록 노력하고 있습니다. 조금 더 작고 이탤릭체로 되어 있지만, 보면 충분히 깨끗해 보이지는 않습니다. 다음은 이미지입니다. 어떤 조언이라도 환영합니다.여기에 이미지 설명을 입력하세요

답변1

이는 귀하의 명령에 대한 올바른 정의여야 합니다 \qweq.

\newcommand{\qweq}[4][!htbp]{%
\begin{figure}[#1]%
\centering%
\includegraphics[width=9cm]{/images/task#2/#3}%
\caption{\emph{\small{#4}}}%
\end{figure}%
}

우선, %불필요한 공백을 피하기 위해 각 줄은 으로 끝난다는 점에 유의하세요(특히 캡션에서...). 또한 네 번째 선택적 인수(기본값은 !htbp)가 환경에 옵션을 전달하는 첫 번째 인수로 제공됩니다 figure.

배치 에 만족하면 !htbp다음과 같이 해당 인수를 전달할 필요가 없습니다.

\qweq{1}{donkey}{This is a donkey eating some grass. Nothing to do with databases but that's no problem.}

으로 변경하려면 다음 !hb과 같이 사용해야 합니다.

\qweq[!hb]{1}{donkey}{This is a donkey eating some grass again.}

MWE

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup[figure]{justification=centering}

\newcommand{\qweq}[4][!htbp]{%
\begin{figure}[#1]%
\centering%
\includegraphics[width=9cm]{/images/task#2/#3}%
\caption{\emph{\small{#4}}}%
\end{figure}%
}

\begin{document}

\qweq{1}{donkey}{This is a donkey eating some grass. Nothing to do with databases but that's no problem.}

\qweq[!hb]{1}{donkey}{This is a donkey eating some grass again.}

\end{document} 

산출

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

의 사용에 유의하세요

\captionsetup[figure]{justification=centering}

Harish Kumar가 자신의 의견에서 제안한 대로 캡션을 중앙에 배치하려면 캡션을 중앙에 배치해야 합니다.

관련 정보