tikz,minipage 和定位问题

tikz,minipage 和定位问题

我正在使用 tikz 和 minipage 在描述列表中创建一个注释框。我面临的问题是,我实际上无法控制 minipage 和相应注释文本的定位。我希望以这样的方式定位注释文本,即周围的文本不会环绕它(我的意思是没有内联嵌入),并且我可以根据页面的布局定位注释框(例如将其放在左边或右边,或者将其放在中心附近等)。有人能建议一种实现上述两个目标的方法吗?MWE 如下。

短暂性脑缺血发作

\documentclass[11pt]{report}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\begin{document}
 \begin{description}
\item[\emph{Point:}] texttexttexttexttexttexttexttexttext... 
 % copied from http://www.texample.net/tikz/examples/boxes-with-text-and-math/
\vspace{3mm}
\begin{tikzpicture}
\node [mybox] (box){%
    \begin{minipage}{0.9\textwidth}
Note text.
    \end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {NOTE};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\end{tikzpicture}
texttexttexttexttexttexttexttexttext...
\end{description}
\end{document}

答案1

首先你的例子:

\documentclass[11pt]{report}
\usepackage{tikz,showframe}
\usetikzlibrary{shapes,positioning}
\tikzset{mybox/.style = {draw=red, fill=blue!20, line width=1pt,
                          rectangle, rounded corners, inner sep=10pt, inner ysep=20pt},
         fancytitle/.style ={fill=red, text=white}
         }
\begin{document}
 \begin{description}
    \item[\emph{Point:}] texttexttexttexttexttexttexttexttext...

    % copied from http://www.texample.net/tikz/examples/boxes-with-text-and-math/
      \vspace{3mm}
       \begin{tikzpicture}
        \node [mybox] (box){%
           \begin{minipage}{\dimexpr\textwidth-\leftmargin-22pt\relax}
             Note text.
           \end{minipage}
          };
        \node[fancytitle, right=10pt] at (box.north west) {NOTE};
        \node[fancytitle, rounded corners,overlay] at (box.east) {$\clubsuit$};
       \end{tikzpicture}

      texttexttexttexttexttexttexttextt
  \end{description}
\end{document}

在此处输入图片描述

现在tcolorbox

\documentclass[11pt]{report}
\usepackage[many]{tcolorbox}
\tikzset{fancytitle/.style ={fill=red, text=white}}
\newtcolorbox{mybox}[2][]{
  enhanced jigsaw,
  width=0.5\textwidth,  %% change
  colback=blue!20,
  colframe=red,
  title=#2,
  boxrule=1pt,
  left=10pt,right=10pt,top=20pt,bottom=20pt,
  attach boxed title to top left= {xshift=10pt,yshift*=-\tcboxedtitleheight/2},
  boxed title style={size=small,colback=red,colframe=green!75!black,arc=0ex},
  before=\par\vspace{3mm},
  after=\par,
  overlay unbroken and first ={
    \node[fancytitle, rounded corners] at (frame.east) {$\clubsuit$};
    },
  #1
}


\begin{document}
 \begin{description}
    \item[\emph{Point:}] texttexttexttexttexttexttexttexttext...
       \begin{mybox}{NOTE}
          Note text.
       \end{mybox}
      texttexttexttexttexttexttexttextt
  \end{description}
\end{document}

在此处输入图片描述

以下是手册中的一个例子:

\documentclass[11pt]{report}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\usepackage{varwidth}
\newtcolorbox{mybox}[2][]{enhanced,
attach boxed title to top left={xshift=1cm,yshift=-2mm},
fonttitle=\bfseries,varwidth boxed title=0.7\linewidth,
colbacktitle=green!45!white,coltitle=green!10!black,colframe=green!50!black,
interior style={top color=yellow!10!white,bottom color=green!10!white},
boxed title style={enhanced,boxrule=0.75mm,colframe=white,
borderline={0.1mm}{0mm}{green!50!black},
borderline={0.1mm}{0.75mm}{green!50!black},
interior style={top color=green!10!white,bottom color=green!10!white,
middle color=green!50!white},
drop fuzzy shadow},
overlay unbroken and first ={
    \node[fill=red, text=white, rounded corners] at (frame.east) {$\clubsuit$};
    },
title={#2},#1}

\begin{document}
 \begin{description}
    \item[\emph{Point:}] texttexttexttexttexttexttexttexttext...
       \begin{mybox}{My title}
         \lipsum[2]
       \end{mybox}
      texttexttexttexttexttexttexttextt
  \end{description}
\end{document}

在此处输入图片描述

相关内容