額入り写真と額入りキャプション

額入り写真と額入りキャプション

Latex ブック ファイルに画像を挿入する必要がありますが、画像はフレームで囲む​​必要があり、画像の後にキャプションも必要です。フレームは同じではなく、画像とキャプションの間には水平線が必要です。ただし、画像は中央に配置する必要があり、キャプションは画像の幅の左に揃える必要があります。誰か助けてくれませんか?

答え1

1 つの解決策 (最も簡単ではないかもしれませんが...) は、captionパッケージを使用してキャプションの上に水平線を追加し、mdframedパッケージを使用して図とキャプションの組み合わせの周囲にフレームを配置することです。

水平線は、\DeclareCaptionFormat3 つの引数 (図番号、区切り文字、キャプション テキスト) の前に置き、その後に改行することで挿入できます。

行をフレーム全体に広げるには、余白を調整する必要がありますが、これは\mdfdefinestyleからで可能ですmdframed

justificationと を組み合わせたオプションを使用すると、キャプションを左揃えにすることができます。ただし、これは、 で指定されている画像の幅ではなく、figure 環境に合わせて配置されます。これは少し複雑ですが、この問題の考えられる解決策は、新しい長さ ( の下にある MWE 内) を導入し、この長さの値を画像の推奨幅に設定し、 と の両方の長さを使用して、キャプション形式で小さな計算を行い、インデントを決定することです。singlelinecheck=false\captionsetup\includegraphics\figwidth\includegraphics

MWE:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{mdframed}
\mdfdefinestyle{boxcaption}{innerleftmargin=0cm,innerrightmargin=0cm}
\newlength{\figwidth}

\DeclareCaptionFormat{myformat}{\hrulefill\newline\hspace*{\dimexpr(\textwidth-\figwidth)/2}#1#2#3}
\captionsetup[figure]{format=myformat,justification=justified,singlelinecheck=false}

\begin{document}
\begin{figure}[tb]
\begin{mdframed}[style=boxcaption]
  \centering
  \setlength{\figwidth}{0.7\textwidth}
     \includegraphics[width=\figwidth]{./fig/test}
  \caption{Left aligned}
  \label{fig:test}
\end{mdframed}
\end{figure}
You can see an example of a black box in Figure \ref{fig:test}.
\end{document}

demoのオプションはブラックgraphicxボックスを表示するだけであり、実際のアプリケーションでは必要ありません。

結果:

枠付きキャプションの例

このソリューションは、図の説明の下の水平線

答え2

\fboxの代わりにを使用した解法を次に示しますmdframed。すべての余白は に設定されました\fboxsep。(この一部は Marijn の解法から借用しました。)

この点については言及しておくべきでしょう\fboxsepが、\fboxrule調整可能です。

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
%\usepackage{mwe}
\usepackage{showframe}% check centering

\captionsetup[figure]{justification=justified,singlelinecheck=false}%

\newcommand{\pictureframe}[2]% #1=image, #2=caption
{\sbox0{#1}%
\centering
\fbox{\begin{minipage}{\wd0}
  \baselineskip=0pt
  \abovecaptionskip=\fboxsep
  \belowcaptionskip=0pt
  \usebox0\par
  \vspace{\fboxsep}%
  \hspace{-\fboxsep}% extend to frame
  \rule{\dimexpr \textwidth+2\fboxsep}{\fboxrule}%
  \hspace{-\fboxsep}
  \caption{#2}
\end{minipage}}}

\begin{document}
\begin{figure}
\pictureframe{\includegraphics[height=2in]{example-image}}{Left aligned}
\end{figure}
\end{document}

額入りの絵

関連情報