LaTeX forum ⇒ Graphics, Figures & TablesBox 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

Postby wishotz » Sun Jan 08, 2017 5:18 pm

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

  1. --Text-------
  2. | |
  3. | |
  4. -------------


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.

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8032
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Jan 08, 2017 6:05 pm

You could use tcolorbox, for example:

  1. \documentclass{article}
  2. \usepackage[most]{tcolorbox}
  3. \newtcolorbox{mybox}[2][]{%
  4. attach boxed title to top center
  5. = {yshift=-8pt},
  6. colback = blue!5!white,
  7. colframe = blue!75!black,
  8. fonttitle = \bfseries,
  9. colbacktitle = blue!85!black,
  10. title = #2,#1,
  11. enhanced,
  12. }
  13. \begin{document}
  14. \begin{mybox}[colback=white]{Title}
  15. This is my box.
  16. \end{mybox}
  17. \end{document}


box.png
box.png (3.25 KiB) Viewed 263 times


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

Stefan
Site admin

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

Postby wishotz » Sun Jan 08, 2017 6:23 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

User avatar
Stefan Kottwitz
Site Admin
Posts: 8032
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Jan 08, 2017 6:29 pm

You could add a width option, such as:

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

Stefan
Site admin

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

Postby wishotz » Sun Jan 08, 2017 6:37 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

User avatar
Stefan Kottwitz
Site Admin
Posts: 8032
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Jan 08, 2017 6:43 pm

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
Site admin

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

Postby wishotz » Sun Jan 08, 2017 6:51 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?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8032
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Jan 08, 2017 7:04 pm

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.

  1. \documentclass{article}
  2. \usepackage[most]{tcolorbox}
  3. \newtcolorbox{mybox}[2][]{%
  4. attach boxed title to top center
  5. = {yshift=-8pt},
  6. colback = blue!5!white,
  7. colframe = blue!75!black,
  8. fonttitle = \bfseries,
  9. colbacktitle = blue!85!black,
  10. title = #2,#1,
  11. enhanced,
  12. }
  13. \begin{document}
  14. \begin{tabular}{cccc}
  15. \begin{mybox}[colback = white, width = 2cm]{Title}
  16. First box.
  17. \end{mybox}
  18. &
  19. \begin{mybox}[colback = white, width = 3cm]{Title}
  20. This is my second box.
  21. \end{mybox}
  22. &
  23. \begin{mybox}[colback = white, width = 1.8cm]{Title}
  24. One more.
  25. \end{mybox}
  26. &
  27. \begin{mybox}[colback = white, width = 2cm]{Title}
  28. Last one.
  29. \end{mybox}
  30. \end{tabular}
  31. \end{document}


boxes.png
boxes.png (8.28 KiB) Viewed 243 times


Stefan
Site admin

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

Postby wishotz » Sun Jan 08, 2017 7:10 pm

Thanks

kostao
Posts: 16
Joined: Tue Jan 10, 2017 8:48 pm

Postby kostao » Wed Jan 11, 2017 9:35 am

I try to compile this code
  1. \documentclass{article}
  2. \usepackage[most]{tcolorbox}
  3. \usepackage{varwidth}
  4. \usepackage{lipsum}
  5.  
  6. \newtcolorbox
  7. {mybox}[2][]{enhanced,
  8. before skip=2mm,after skip=2mm,
  9. colback=black!5,colframe=black!50,boxrule=0.2mm,
  10. attach boxed title to top left={xshift=1cm,yshift*=1mm-
  11. \tcboxedtitleheight
  12. },
  13. varwidth boxed title*=-3cm,
  14. boxed title style={frame code={
  15. \path[fill=tcbcol@back!30!black]
  16. ([yshift=-1mm,xshift=-1mm]frame.north west)
  17. arc[start angle=0,end angle=180,radius=1mm]
  18. ([yshift=-1mm,xshift=1mm]frame.north east)
  19. arc[start angle=180,end angle=0,radius=1mm];
  20. \path[left color=tcbcol@back!60!black,right color=tcbcol@back!60!black,
  21. middle color=tcbcol@back!80!black]
  22. ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
  23. [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
  24. -- (frame.south east) -- (frame.south west)
  25. -- ([xshift=-1mm,yshift=-1mm]frame.north west)
  26. [sharp corners]-- cycle;
  27. },interior engine=empty,
  28. },
  29. fonttitle=\bfseries,
  30. title={#2},#1}
  31.  
  32. \begin{document}
  33. \begin{mybox}[colbacktitle=green]{My title}
  34. \lipsum[2]
  35. \end{mybox}
  36. \begin{mybox}[colbacktitle=red]{My title}
  37. \lipsum[3]
  38. \end{mybox}
  39. \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.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 3 guests