4

Is there any LaTeX package that can produce tables and figures like the example in the folowing image by default?

wanted

EDIT:

I used tcolorbox but I did not get the result needed as I'm not familiar with its options. here is my code (I found it here)

\newtcolorbox{theorem}[1][]{
breakable,
enhanced,
colback=white,
colframe=black,
top=\baselineskip,
enlarge top by=\topsep,
overlay unbroken and first={
  \node[xshift=100pt,thick,draw=black,fill=white,anchor=west] at (frame.north west) %
  {\refstepcounter{theorem}\strut{\bfseries\theoname~\thetheorem}\if#1\@empty\relax\relax\else~: #1\fi};
  }
}

and this is the result enter image description here

How can I customise it in order to be similar to the above one?

user42987
  • 333
  • 1
    Welcome to TeX.SX! I think you're looking for pgfplots package. – Claudio Fiandrino May 12 '14 at 07:42
  • Thak you for your quick response, but I'm not looking for producing a graph, I'm just looking for the formatting above – user42987 May 12 '14 at 07:45
  • 1
    'By default' is a bit of a broad term here: as already mentioned, there are packages such as pgfplots that can make plots, but you will have to make changes to get a good reproduction of the example. – Joseph Wright May 12 '14 at 07:45
  • 1
    @user42987: I've likely misunderstood, but after reading: "Is there any package in Latex that can produce table and figure [..]", I think is pretty normal to suggest a package that can draw the figure. Could you be more specific then? – Claudio Fiandrino May 12 '14 at 08:00
  • May be it's my fault, I'm not a native English speaker. The graphics (charts for example) are produced using R and are exported as pdf files and included in the Latex document.

    I want a box around the graphics included that containd the number of figure and the caption.

    – user42987 May 12 '14 at 08:07
  • 1
    Have you tried to use the float environnement? – Romain Picot May 12 '14 at 08:12
  • 1
    You could take a look at the tcolorbox or mdframed packages, combined with the caption package. – Bernard May 12 '14 at 09:01
  • @Bernard, That's funny :p , I'm already looking on the tcolorbox package now, thanks – user42987 May 12 '14 at 09:11
  • I have edited my post by putting my essay, can you help please? – user42987 May 12 '14 at 10:53
  • 1
    Maybe you can use nested tables and multicolums. – Sveinung May 12 '14 at 13:56

2 Answers2

4

How about this solution using tcolorbox ?

\documentclass{article}
\usepackage[many]{tcolorbox}

\newtcolorbox[auto counter]{myfigure}[2][]{enhanced,center upper,
  colback=white,colbacktitle=black!20!white,coltitle=black,
  arc=0pt,outer arc=0pt,fonttitle=\scshape,lefttitle=2.4cm,
  boxrule=0.3mm,
  overlay={
    \fill[black!20!white] ([xshift=2.2cm,yshift=-0.3mm]title.south west) rectangle (frame.north east);
    \fill[black] ([yshift=-0.3mm]title.south west) rectangle
      node[white] {\sffamily Figure~\thetcbcounter}
      ([xshift=2.2cm]title.north west);
  },title={#2},#1}

\begin{document}

\begin{myfigure}{Prevalence des Prescriptions des Molecules d'Antibiotiques
  les plus Frequntes, par Annee d'Enquete}
\includegraphics[width=10cm]{example-image-a}
\end{myfigure}

\end{document}

enter image description here

If this new figure should contain the chapter number and behave like an 'ordinary' LaTeX figure, use the following modification:

\newtcolorbox[use counter=figure,number within=chapter,
  list inside=lof,list type=figure]{myfigure}[2][]{enhanced,center upper,
  colback=white,colbacktitle=black!20!white,coltitle=black,
  arc=0pt,outer arc=0pt,fonttitle=\scshape,lefttitle=2.4cm,
  boxrule=0.3mm,
  overlay={
    \fill[black!20!white] ([xshift=2.2cm,yshift=-0.3mm]title.south west) rectangle (frame.north east);
    \fill[black] ([yshift=-0.3mm]title.south west) rectangle
      node[white] {\sffamily Figure~\thetcbcounter}
      ([xshift=2.2cm]title.north west);
  },title={#2},#1}

Then, the new figure will be listed inside the list of figures using

\listoffigures
  • Thak you for your help, this is what I expected, but I got an error when compiling: Unknown option many for package tcolorbox. \ProcessOptions* – user42987 May 12 '14 at 17:15
  • I will try to update packages and tell you – user42987 May 12 '14 at 17:35
  • 1
    I quite sure that you have an old version of tcolorbox. The current version is 3.00. After an update, it should work. – Thomas F. Sturm May 12 '14 at 17:35
  • Worked perfectly ! I did not find words to thank you ! – user42987 May 12 '14 at 18:05
  • please how can I change the code in order to increment with the chapter; for example : figure 2.3 (it means the third figure in the second chapte) I found this command \refstepcounter but I dont know how to use it. I also want the box to be referenced in the table of figure with its name. thanks – user42987 May 12 '14 at 18:28
  • I found the option for the the counter, I used number within=chapter option – user42987 May 12 '14 at 19:14
  • 1
    @user42987 I'm glad that I could help. Maybe, it's also useful to know for you that you can make the figure floatable by adding the option float to the keylist or - more flexible - individually by using \begin{myfigure}[float]{... – Thomas F. Sturm May 13 '14 at 08:28
  • I want all the new box to be listed in the list of figure. How can I do that? – user42987 May 13 '14 at 12:49
  • 1
    @user42987 See my updated answer. – Thomas F. Sturm May 13 '14 at 13:10
  • Unfortunately there is no way to accept an answer twice :)) , Your answer worked perfectly. I even change lof by lot to include the box in the list of table – user42987 May 13 '14 at 13:25
2

If you only want to draw the graph, I suggest you have a look at a drawing program using LaTeX or producing LaTeX-code.

One program is Ipe v 7. Another program is Nicola Talbot’s jpgfdraw.

Ipe is using LaTeX to produced PDF-files you may include in the main document.

Sveinung
  • 20,355
  • Thak you for your help, I'm not looking for producing graphics, I Just want to produce a box (similar to the one above) around my included plots that contain the number of the figure and the caption. – user42987 May 12 '14 at 08:12
  • 1
    @user42987 Then just put the picture in an ‘fbox’. – Sveinung May 12 '14 at 08:19
  • 1
    @user42987 You may also try ‘framebox’, http://www.forkosh.com/latex/ltx-237.html – Sveinung May 12 '14 at 08:23