虚假空间?取决于 keepaspectratio

虚假空间?取决于 keepaspectratio

请检查以下 MWE:

\documentclass{article}

\usepackage[showframe]{geometry}
\usepackage{mwe}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage[framemethod=tikz]{mdframed}

\mdfdefinestyle{mystyle1}{
  apptotikzsetting={\tikzset{mdfbackground/.style={},}},
  extra={
    \scoped[on background layer]{
      \node
        [xshift=.5*\mdfboundingboxwidth, yshift=.5*\mdfboundingboxheight, opacity=.4]
        {\includegraphics
          [width=\mdfboundingboxwidth, height=\mdfboundingboxheight]
          {example-image}
        };
    }
  }
}

\mdfdefinestyle{mystyle2}{
  apptotikzsetting={\tikzset{mdfbackground/.style={},}},
  extra={
    \scoped[on background layer]{
      \node
        [xshift=.5*\mdfboundingboxwidth, yshift=.5*\mdfboundingboxheight, opacity=.4]
        {\includegraphics
          [width=\mdfboundingboxwidth, height=\mdfboundingboxheight, keepaspectratio]
          {example-image}
        };
    }
  }
}

\mdfdefinestyle{mystyle3}{
  apptotikzsetting={\tikzset{mdfbackground/.style={},}},
  extra={
    \scoped[on background layer]{
      \node
        [xshift=.5*\mdfboundingboxwidth, yshift=.5*\mdfboundingboxheight, opacity=.4]
        {\includegraphics
          [width=\mdfboundingboxwidth, height=\mdfboundingboxheight, keepaspectratio=true]
          {example-image}
        };
    }
  }
}

\mdfdefinestyle{mystyle4}{
  apptotikzsetting={\tikzset{mdfbackground/.style={},}},
  extra={
    \scoped[on background layer]{
      \node
        [xshift=.5*\mdfboundingboxwidth, yshift=.5*\mdfboundingboxheight, opacity=.4]
        {\includegraphics
          [width=\mdfboundingboxwidth, height=\mdfboundingboxheight, keepaspectratio=false]
          {example-image}
        };
    }
  }
}


\begin{document}
  \begin{mdframed}[style=mystyle1]
    mystyle1
    \blindtext
  \end{mdframed}
  \begin{mdframed}[style=mystyle2]
    mystyle2
    \blindtext
  \end{mdframed}
  \begin{mdframed}[style=mystyle3]
    mystyle3
    \blindtext
  \end{mdframed}
  \begin{mdframed}[style=mystyle4]
    mystyle4
    \blindtext
  \end{mdframed}
\end{document}

以下是相应的输出: 在此处输入图片描述

mystyle1和的间距问题mystyle4出在哪里(框架与主体错位)?这可能是一个错误吗?

问候,伊凡

答案1

在此处输入图片描述

您需要将内部分离设置为零,为全宽图像留出空间,如此处的情况 4 所示。

    [inner sep = 0pt,xshift=.5*\mdfboundingboxwidth, yshift=.5*\mdfboundingboxheight, opacity=.4]
     %%%%%%%%%%%%%%%%

相关内容