3

How to draw dotted box(like rounded dot) in tcolorbox instead of square line boxes, I tried but output shown like square line not rounded dot? Please find my MWE files:

\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}

enter image description here

6

hm, it seems that you like to have something the following:

enter image description here

it is obtained by use of decorations.shapes tikz library:

\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}

addendum: in case, that you like to have rounded corners of box too, ans use it only in some float environment, than the code can be shorten and modified to the following:

\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}

which gives:

which gives

  • 1
    Yes I got the required output, Thank you Zarko. – Rajesh N Jun 3 at 12:00
1

You can hide the frame and draw a dotted rectangle with rounded corners:

\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}

enter image description here

  • Visually it looks fine but problem is that while zooming dotted line shown like small square box instead of rounded dot. – Rajesh N Jun 3 at 11:12
  • I like it and I vote it positively :-) – Sebastiano Jun 3 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.