如何定义图形、表格等附加浮动环境?

如何定义图形、表格等附加浮动环境?

我找到了这个关于如何围绕内容构建一个框非常喜欢这个想法。我已经在几个地方用过它了,但现在遇到了一点小问题。

我有一个框,大约有 3/4 页高,有点撕裂我的文档。我想做的是让这个框浮动,而其他框则保持原位。

如果这些框可以像表格一样有标题,那就太好了,但我希望将它们放在框架的“标题”部分。如果可以的话。

下面我附上了一个关于布局的示例源代码。第一部分的第一页上有太多的白色,而第二部分的情况也好不到哪里去。

            \documentclass{article}
            \usepackage{tikz}
            \usetikzlibrary{positioning}
            \usepackage{lipsum}
            \usepackage{tcolorbox}
            \newtcolorbox{mybox}{colback=black!5!white,colframe=blue!75!black}
            \newtcolorbox{myboxtitle}[1]{colback=green!5!white,colframe=green!75!white,title=#1} %fonttitle=\bfseries

            \begin{document}

            \section{How it is}
            \lipsum[7]
                    \begin{myboxtitle}{Naming Convention for CC}
                    \lipsum[2]
                    \end{myboxtitle}
            \lipsum[8]
                    \begin{myboxtitle}{Naming Convention for CC}
                \lipsum[3]
                            \begin{minipage}[t][4.2cm][c]{\linewidth}
                        \end{minipage}  
                \lipsum[6]
                    \end{myboxtitle}       
            \lipsum[7-10]

            \newpage
            \section{How it would be better}
            \lipsum[7]
                \begin{figure} %this should be the new environment. Would be great to combine with the box
                    \begin{myboxtitle}{Naming Convention for CC}
                    Well, this should not float to the top!
                    \end{myboxtitle}
                    \end{figure}
            \lipsum[8]
                \begin{figure}
                    \begin{myboxtitle}{Naming Convention for CC}
                \lipsum[3]
                            \begin{minipage}[t][4.2cm][c]{\linewidth}
                    \huge This box should not be alone on one page.
                        \end{minipage}  
                \lipsum[6]
                    \end{myboxtitle}     
                    \end{figure}  
            \lipsum[7-12]


            \end{document}

感谢您的帮助!

答案1

还没有完全完成,但正如我所说,已经正确浮动。只需使用环境float选项即可tcolorbox

 \documentclass{article}
  \usepackage{tikz}
  \usetikzlibrary{positioning}
  \usepackage{lipsum}
  \usepackage[most]{tcolorbox}
  \newtcolorbox{mybox}{colback=black!5!white,colframe=blue!75!black,float}
  \newtcolorbox[auto counter,number within=section]{myboxtitle}[2][]{colback=green!5!white,colframe=green!75!white,title={#2},float,#1} %fonttitle=\bfseries

  \begin{document}

  \section{How it is}
  \lipsum[7]
          \begin{myboxtitle}{Naming Convention for CC}
          \lipsum[2]
          \end{myboxtitle}
  \lipsum[8]
          \begin{myboxtitle}{Naming Convention for CC}
      \lipsum[3]
                  \begin{minipage}[t][4.2cm][c]{\linewidth}
              \end{minipage}  
      \lipsum[6]
          \end{myboxtitle}       
  \lipsum[7-10]

  \newpage
  \section{How it would be better}
  \lipsum[7]
          \begin{myboxtitle}{Naming Convention for CC}
          Well, this should not float to the top!
          \end{myboxtitle}
  \lipsum[8]
        \begin{myboxtitle}[floatplacement=ht]{Naming Convention for CC}
          \lipsum[3]
          This box should not be alone on one page.
          \lipsum[6]
          \end{myboxtitle}     
  \lipsum[7-12]


  \end{document}

答案2

也许这个float包对你有用:

平均能量损失

\documentclass{article}
\usepackage{float,lipsum,graphicx}
\floatstyle{ruled} % try boxed
\newfloat{fancyfloat}{tb}{fan}[section]
\floatname{fancyfloat}{Fancy float}
\begin{document}
\listof{fancyfloat}{List of fancy floats}

\section{Lore ipsum}

\lipsum[1]

\begin{fancyfloat}
\hfill Some dummy content \dotfill\vrule
\centering
\begin{tabular}{llll}
    11 & 12 & 13 & 14\\
    21 & 22 & 23 & 24\\
    31 & 32 & 33 & 34\\
    41 & 42 & 43 & 44\\
\end{tabular}\hfill
\caption{This is a fancy float}
\end{fancyfloat}

\lipsum[2]

\begin{fancyfloat}[H]
\caption{This is a other fancy float}
\includegraphics[height=2cm]{example-image-a}\hfill
\includegraphics[height=2cm]{example-image-b}\hfill
\includegraphics[height=2cm]{example-image-c}
\end{fancyfloat}
\lipsum[15-30]
\end{document}

答案3

您可以使用图形选项来控制位置(更多或更少)。

        \usepackage{tikz}
        \usetikzlibrary{positioning}
        \usepackage{lipsum}
        \usepackage{tcolorbox}
        \newtcolorbox{mybox}{colback=black!5!white,colframe=blue!75!black}
        \newtcolorbox{myboxtitle}[1]{colback=green!5!white,colframe=green!75!white,title=#1} %fonttitle=\bfseries

        \begin{document}

        \section{How it would be better}
        \lipsum[7]
            \begin{figure}[hbp] %this should be the new environment. Would be great to combine with the box
                \begin{myboxtitle}{Naming Convention for CC}
                Well, this should not float to the top!
                \end{myboxtitle}
                \end{figure}
        \lipsum[8]
            \begin{figure}[!t]
                \begin{myboxtitle}{Naming Convention for CC}
            \lipsum[3]
                        \begin{minipage}[t][4.2cm][c]{\linewidth}
                \huge This box should not be alone on one page.
                    \end{minipage}  
            \lipsum[6]
                \end{myboxtitle}     
                \end{figure}  
        \lipsum[7-12]


        \end{document}

相关内容