我今天學習了一些 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.}
微量元素
\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 在他的評論中所建議的那樣,將標題居中。