Tcolor 框 虚线框

Tcolor 框 虚线框

如何在 tcolorbox 中绘制虚线框(类似圆点)而不是方线框,我试过了,但输出显示为方线而不是圆点?请查看我的 MWE 文件:

\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{tikz}


\tikzstyle{dashedboxone}=[dot pattern=on .5pt off 1.2pt]

\tikzstyle{dashedboxone}=[dot pattern=on .5pt off 1.2pt]

\newtcolorbox{BoxTypeA}{%
enhanced,
breakable,
sharp corners,arc=0pt,outer arc=0pt,
boxrule=2pt,boxsep=0pt,top=4pt,left=4pt,right=4pt,bottom=4pt,middle=0pt,
colback=white, 
colframe=white, 
pad at break=0pt,bottomrule at break=0pt,toprule at break=0pt,
borderline east={0.5pt}{-0.25pt}{black,dotted},
borderline west={0.5pt}{-0.25pt}{black,dotted},
borderline south={0.5pt}{-0.25pt}{black,dotted},
borderline north={0.5pt}{-0.25pt}{black,dotted},
fontupper={\fontsize{9bp}{11bp}\selectfont\ttfamily}
}%

\begin{document}

\begin{figure}[t!]
\begin{BoxTypeA}
\# GET reads the keyboard.FIGURE\\
\# READ loads data from a disk file.\\
\# DISPLAY shows output on screen.\\
\# WRITE saves output to a file.\\
DISPLAY “What is your name?”\\
GET UserName\\
OPEN FILE “Users.txt”\\
READ data for UserName\\
IF new data exists THEN\\
WRITE new data to file\\
END IF
\end{BoxTypeA}
\caption{GET reads the keyboard. GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.}
\end{figure}

\end{document}

在此处输入图片描述

答案1

嗯,看来你喜欢下面这样的东西:

在此处输入图片描述

它是通过使用decorations.shapestikz 库获得的:

\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.shapes}

\tikzset{
  decoration = {shape backgrounds, shape=circle,
                shape size=0.25pt, shape sep=2pt},
paint/.style = {decorate, fill=black}
}

\newtcolorbox{BoxTypeA}{%
enhanced,
breakable,
sharp corners,
boxrule=2pt,boxsep=0pt,top=4pt,left=4pt,right=4pt,bottom=4pt,middle=0pt,
colback=white,
colframe=white,
pad at break=0pt,bottomrule at break=0pt,toprule at break=0pt,
borderline={0pt}{0pt}{paint},
}%

\begin{document}
    \begin{figure}[t!]
\begin{BoxTypeA}
\# GET reads the keyboard.FIGURE\\
\# READ loads data from a disk file.\\
\# DISPLAY shows output on screen.\\
\# WRITE saves output to a file.\\
DISPLAY “What is your name?”\\
GET UserName\\
OPEN FILE “Users.txt”\\
READ data for UserName\\
IF new data exists THEN\\
WRITE new data to file\\
END IF
\end{BoxTypeA}
\caption{GET reads the keyboard. GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.}
    \end{figure}
\end{document}

附录: 如果您也喜欢盒子的圆角,并且仅在某些浮动环境中使用它,那么可以缩短并修改代码如下:

\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{decorations.shapes}

\tikzset{
  decoration = {shape backgrounds, shape=circle,
                shape size=1pt, shape sep={4pt, between centers}
                },
paint/.style = {decorate, fill=black}
}

\newtcolorbox{BoxTypeA}{%
enhanced,
    boxsep=0mm, left=4pt,
    arc=4pt,
    colback=white,
    colframe=white,%
pad at break=0pt,bottomrule at break=0pt,toprule at break=0pt,
borderline={0pt}{0pt}{paint},
}%

\newtcolorbox{BoxTypeB}{%
enhanced,
sharp corners,
boxrule=2pt,boxsep=0pt,top=4pt,left=4pt,right=4pt,bottom=4pt,middle=0pt,
colback=white,
colframe=white,
borderline={0pt}{0pt}{paint},
}%

\begin{document}
   \begin{figure}[htb]
\begin{BoxTypeA}
    \# GET reads the keyboard.FIGURE\\
    \# READ loads data from a disk file.\\
    \# DISPLAY shows output on screen.\\
    \# WRITE saves output to a file.\\
    DISPLAY “What is your name?”\\
    GET UserName\\
    OPEN FILE “Users.txt”\\
    READ data for UserName\\
    IF new data exists THEN\\
    WRITE new data to file\\
    END IF
\end{BoxTypeA}
\caption{GET reads the keyboard. GET reads the keyboard. GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.}
    \end{figure}
\end{document}

这使:

这使

答案2

您可以隐藏框架并绘制一个带圆角的虚线矩形:

\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{tikz}


\tikzstyle{dashedboxone}=[dot pattern=on .5pt off 1.2pt]

\tikzstyle{dashedboxone}=[dot pattern=on .5pt off 1.2pt]

\newtcolorbox{BoxTypeA}{%
enhanced,
breakable,
%sharp corners,arc=0pt,outer arc=0pt,
boxrule=2pt,boxsep=0pt,top=4pt,left=4pt,right=4pt,bottom=4pt,middle=0pt,
colback=white, 
colframe=red, 
frame hidden,
overlay={\draw[dotted, rounded corners=5mm] (frame.south west) rectangle (frame.north east);},
pad at break=0pt,bottomrule at break=0pt,toprule at break=0pt,
%borderline east={0.5pt}{-0.25pt}{black,dotted},
%borderline west={0.5pt}{-0.25pt}{black,dotted},
%borderline south={0.5pt}{-0.25pt}{black,dotted},
%borderline north={0.5pt}{-0.25pt}{black,dotted},
fontupper={\fontsize{9bp}{11bp}\selectfont\ttfamily}
}%

\begin{document}

\begin{figure}[t!]
\begin{BoxTypeA}
\# GET reads the keyboard.FIGURE\\
\# READ loads data from a disk file.\\
\# DISPLAY shows output on screen.\\
\# WRITE saves output to a file.\\
DISPLAY “What is your name?”\\
GET UserName\\
OPEN FILE “Users.txt”\\
READ data for UserName\\
IF new data exists THEN\\
WRITE new data to file\\
END IF
\end{BoxTypeA}
\caption{GET reads the keyboard. GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.GET reads the keyboard. GET reads the keyboard. GET reads the keyboard.}
\end{figure}

\end{document}

在此处输入图片描述

相关内容