既存のフロートの背景色(新しい環境を定義せずに)?

既存のフロートの背景色(新しい環境を定義せずに)?

すべての図(キャプションを含む)の背景に適切な色を付けようとしています。

私はすでに、いくつかの素晴らしい回答がある以下の質問を見つけました:

しかし、これらすべての回答に共通するのは、図の中に配置したり、図を完全に置き換えたりする必要がある新しい環境やコマンドを定義している点です。

背景色を設定する方法はありますか?既存 既存のフロートの内容を変更せずにフロートを追加することはできますか?

答え1

ここに画像の説明を入力してください

\documentclass{article}

\makeatletter

\def\foo#1\normalcolor\vbox\bgroup#2!!{%
\def\@xfloat ##1[##2]{#1%
 \normalcolor
      \hbox\bgroup{\color{yellow}\leaders\vrule\hskip\columnwidth\hskip-\columnwidth}%
      \vbox \bgroup\aftergroup\egroup
#2}}
\expandafter\foo\@xfloat{#1}[#2]!!

\makeatother

\usepackage{color}
\begin{document}

\begin{figure}
a\\b\\c
\caption{yes no}
\end{figure}

one two three

\end{document}

答え2

以下は、mdframed環境を再定義します(したがって、ドキュメント内のfigureの使用法は適応されません)。figure

ここに画像の説明を入力してください

\documentclass{article}
\usepackage{lipsum,mdframed,xcolor}% http://ctan.org/pkg/{lipsum,mdframed,xcolor}
\let\oldfigure\figure% Store old figure environment start
\let\endoldfigure\endfigure% Store old figure environment end
\renewenvironment{figure}[1][htbp]% Redefine figure
  {\oldfigure[#1]\mdframed[backgroundcolor=blue!15]}
  {\endmdframed\endoldfigure}
\begin{document}
\lipsum[1]
\begin{figure}[ht]
  \centering\includegraphics{example-image-a}
  \caption{This is a figure}
\end{figure}
\lipsum[2]
\end{document}

ここから、異なるフロート (たとえば、) に異なるスタイルを適用するのは簡単ですtable

関連情報