## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Box with Title Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
wishotz
Posts: 15
Joined: Mon Dec 26, 2016 2:39 pm

### Box with Title

Hello guys,
I have a small question about tikzpicture.
My aim is to create something similar to something like that

--Text-------|           ||           |-------------

It should be like a box without gaps of course. So I cant just use a usual fbox.

My second question is to create something like a table and in the table squares should be boxes like surveys are.

ty
Last edited by Stefan Kottwitz on Sun Jan 08, 2017 5:55 pm, edited 1 time in total.
Reason: marked as code to better see the box (in monospace font)

Stefan Kottwitz
Posts: 7881
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
You could use tcolorbox, for example:

\documentclass{article}\usepackage[most]{tcolorbox}\newtcolorbox{mybox}[2][]{%  attach boxed title to top center               = {yshift=-8pt},  colback      = blue!5!white,  colframe     = blue!75!black,  fonttitle    = \bfseries,  colbacktitle = blue!85!black,  title        = #2,#1,  enhanced,}\begin{document}\begin{mybox}[colback=white]{Title}This is my box.\end{mybox}\end{document}

box.png (3.25 KiB) Viewed 91 times

For the other question, please open a new topic. One topic for each question is the best.

Stefan

wishotz
Posts: 15
Joined: Mon Dec 26, 2016 2:39 pm
Hey thanks it works great, and how do i use parameters to make the box smaller? Its right now for whole line but i want to make several small ones in one line

Stefan Kottwitz
Posts: 7881
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
You could add a width option, such as:

\begin{mybox}[colback = white, width = 4cm]{Title}

Stefan

wishotz
Posts: 15
Joined: Mon Dec 26, 2016 2:39 pm
Well thats only the width of the box and what about the size of the title box? and also i want 4 such boxes next to each other with differenz sizes

Stefan Kottwitz
Posts: 7881
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
The width of the title box is automatically adjusted to the title text width. So that should be fine. Of course you can override that. There may be a TikZ option, but a quick way I see is making the title text box itself wider, at text level:

\begin{mybox}[colback = white, width = 4cm]{\protect{\makebox[2cm][c]{Title}}}

Stefan

wishotz
Posts: 15
Joined: Mon Dec 26, 2016 2:39 pm
Stefan Kottwitz wrote:The width of the title box is automatically adjusted to the title text width. So that should be fine. Of course you can override that. There may be a TikZ option, but a quick way I see is making the title text box itself wider, at text level:

\begin{mybox}[colback = white, width = 4cm]{\protect{\makebox[2cm][c]{Title}}}

Stefan

Okay sounds good and how can i place 4 of these boxes next to each other?

Stefan Kottwitz
Posts: 7881
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
It seems that simply putting one after the other results in the next one placed below. They seem to end the line.

What came first to my mind, is using tabular, since it can be a good way anyway to have a tabular layout.

\documentclass{article}\usepackage[most]{tcolorbox}\newtcolorbox{mybox}[2][]{%  attach boxed title to top center               = {yshift=-8pt},  colback      = blue!5!white,  colframe     = blue!75!black,  fonttitle    = \bfseries,  colbacktitle = blue!85!black,  title        = #2,#1,  enhanced,}\begin{document}\begin{tabular}{cccc}\begin{mybox}[colback = white, width = 2cm]{Title}First box.\end{mybox}&\begin{mybox}[colback = white, width = 3cm]{Title}This is my second box.\end{mybox}&\begin{mybox}[colback = white, width = 1.8cm]{Title}One more.\end{mybox}&\begin{mybox}[colback = white, width = 2cm]{Title}Last one.\end{mybox}\end{tabular}\end{document}

boxes.png (8.28 KiB) Viewed 71 times

Stefan

wishotz
Posts: 15
Joined: Mon Dec 26, 2016 2:39 pm
Thanks

kostao
Posts: 9
Joined: Tue Jan 10, 2017 8:48 pm
I try to compile this code
\documentclass{article}\usepackage[most]{tcolorbox}\usepackage{varwidth}\usepackage{lipsum} \newtcolorbox{mybox}[2][]{enhanced,before skip=2mm,after skip=2mm,colback=black!5,colframe=black!50,boxrule=0.2mm,attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight},varwidth boxed title*=-3cm,boxed title style={frame code={\path[fill=tcbcol@back!30!black]([yshift=-1mm,xshift=-1mm]frame.north west)arc[start angle=0,end angle=180,radius=1mm]([yshift=-1mm,xshift=1mm]frame.north east)arc[start angle=180,end angle=0,radius=1mm];\path[left color=tcbcol@back!60!black,right color=tcbcol@back!60!black,middle color=tcbcol@back!80!black]([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)[rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)-- (frame.south east) -- (frame.south west)-- ([xshift=-1mm,yshift=-1mm]frame.north west)[sharp corners]-- cycle;},interior engine=empty,},fonttitle=\bfseries,title={#2},#1} \begin{document}\begin{mybox}[colbacktitle=green]{My title}\lipsum[2]\end{mybox}\begin{mybox}[colbacktitle=red]{My title}\lipsum[3]\end{mybox}\end{document}

In overleaf.com it works good, but on my computer (TeXstudio 2.6.6, compiler=xelatex) there is error: pgfkeys: I do not know the key '/tcb/before skip' and I am going to ignore it. Perhaps you misspelled it. \begin{Newbox}[colbacktitle=green]{My title}

How fix it?
Thanks.