1

Thank you very much. I could do the boxes using your comments. The one thing I am having problem is how to align the first and second box (China and EE.UU.). Here is my minimal example (I am writong all the text in each box so you can better understand):

.....

    \tikzstyle{mybox} = [draw=blue!70!black, fill=blue!5!white, very thick,
        rectangle, rounded corners, inner sep=10pt, inner ysep=10pt]
    \tikzstyle{fancytitle} =[fill=blue!70!black, text=white]

    \begin{tikzpicture}

    % First box
    \node [mybox] (box1){%
        \begin{minipage}{0.30\textwidth}
        \begin{multicols}{2}   
          \small Alúmina\\Aluminio prim.\\Antimonio (P. M.)\\Arsénico blanco\\Barita\\Bismuto (P. M.)\\Cadmio\\Carbón\\Cobalto\\Cobre (P. R.)\\Cobre (P. F.)\\Fluorita\\Galio prim.\\Germanio metál.\\Oro (P. M.)\\Grafito\\Yeso\\Indio (P. R.)\\Hierro (mena)\\Arrabio\\Acero bruto\\Plomo (P. M.)\\Plomo (P. R.)\\
    Magnesita\\Megnesio metál. prim.\\Manganeso (mena)\\Mercurio\\Mica\\Molibdeno (P. M.)\\Níquel (P. R./P.F.)\\Perlita\\Roca fosfórica\\Óx. de tierras raras\\Sal\\Min. de estroncio\\Piritas\\Talco\\Estaño (P. M.)\\Estaño (P. F.)\\Tungsteno (P. M.)\\Vanadio (P. M.)\\Wollastonita\\Zinc (P. M.)\\Zinc (planchas)
        \end{multicols}
        \end{minipage}
    };
    \node[fancytitle] at (box1.north) {\textbf{China}};

    %
    \node [mybox,right=2mm of box1.58] (box2) {%
        \begin{minipage}[t!]{0.25\textwidth}
           \small Bentonita\\Tierra de batán\\Berilio\\Bromo\\Diatomita\\Caolín\\Gas natural\\Carb. de sodio natural\\Sulfuro (recuperado)\\Telurio metál.
        \end{minipage}
        };

% Now draw the fancy title (so that it is on top of the connection box)
\node[fancytitle] at (box2.north) {\textbf{EE.UU.}};

..... 

it works very well but I just can´t figure the number next in box2 to align with the fisrt one: 58, 57.9. I tink I am missing something?

Thank you very much!!

  • (1) Welcome, (2) please post some code we can work from. – daleif Oct 6 '15 at 13:27
  • Everything in the picture should be easy (assuming you already have the flags) except the non-rectangular China box. – John Kormylo Oct 6 '15 at 13:38
  • While I'm not sure where (in 1cm of box2.south) is supposed to be, it obviously does not correspond to tikz protocols. ($(box2.south) + (-1cm,0cm)$) locates a point 1 cm to the left of box2.south, but you need the calc tikzlibrary. \node[left=1cm] at (box2.south) is simpler. – John Kormylo Oct 6 '15 at 13:40
  • 1
    It's difficult to say without the actual code, but a similar error happened to me when I forgot to add \usetikzlibrary{positioning}, which I think is needed for expressions like below=1cm of box2.south. – LucaD Oct 6 '15 at 13:47
  • @LucaD is correct that the positioning library is required for that syntax, and you'll see the Martin Scharrer has that in his preamble in the other question. – Torbjørn T. Oct 6 '15 at 15:29
2

Please always post a complete example. We have no idea what \textwidth is, for example, and it is necessary to guess the packages and libraries required to even get something to compile.


It isn't clear what exactly you want aligned as you are specifying a precise aligiment with .58. If you want the boxes aligned at the top, one way is to use .north east and anchor=north west:

aligned north

\documentclass{article}
\usepackage{multicol,tikz}
\usetikzlibrary{positioning}
\tikzset{
  mybox/.style={draw=blue!70!black, fill=blue!5!white, very thick, rectangle, rounded corners, inner sep=10pt, inner ysep=10pt},
  fancytitle/.style={fill=blue!70!black, text=white},
}
\begin{document}
\begin{tikzpicture}
  % First box
  \node [mybox] (box1){%
    \begin{minipage}{0.30\textwidth}
      \begin{multicols}{2}
        \small Alúmina\\Aluminio prim.\\Antimonio (P. M.)\\Arsénico blanco\\Barita\\Bismuto (P. M.)\\Cadmio\\Carbón\\Cobalto\\Cobre (P. R.)\\Cobre (P. F.)\\Fluorita\\Galio prim.\\Germanio metál.\\Oro (P. M.)\\Grafito\\Yeso\\Indio (P. R.)\\Hierro (mena)\\Arrabio\\Acero bruto\\Plomo (P. M.)\\Plomo (P. R.)\\
        Magnesita\\Megnesio metál. prim.\\Manganeso (mena)\\Mercurio\\Mica\\Molibdeno (P. M.)\\Níquel (P. R./P.F.)\\Perlita\\Roca fosfórica\\Óx. de tierras raras\\Sal\\Min. de estroncio\\Piritas\\Talco\\Estaño (P. M.)\\Estaño (P. F.)\\Tungsteno (P. M.)\\Vanadio (P. M.)\\Wollastonita\\Zinc (P. M.)\\Zinc (planchas)
      \end{multicols}
    \end{minipage}
  };
  \node[fancytitle] at (box1.north) {\textbf{China}};
  \node [mybox, right=2mm of box1.north east, anchor=north west] (box2) {%
    \begin{minipage}[t!]{0.25\textwidth}
      \small Bentonita\\Tierra de batán\\Berilio\\Bromo\\Diatomita\\Caolín\\Gas natural\\Carb. de sodio natural\\Sulfuro (recuperado)\\Telurio metál.
    \end{minipage}
  };
  % Now draw the fancy title (so that it is on top of the connection box)
  \node[fancytitle] at (box2.north) {\textbf{EE.UU.}};
\end{tikzpicture}
\end{document}

However, this is not the best way of drawing boxes like this, in my opinion. You would probably find it a lot easier to use something like tcolorbox. Nesting multiple columns within a minipage within a node just cannot be good....

The code above, for example, produces no fewer than 25 bad boxes. The use of \\ to end lines is partly responsible - this ought (very nearly almost) never be used outside tabular and array environments etc.


Here's an alternative based on tcolorbox. It sets up a new environment listingbox with the following syntax for a one-column box:

\begin{listingbox}[<additional options for box>]{<title>}
    <contents>
\end{listingbox}

or the following for a two-column version using the starred version:

\begin{listingbox}*[<additional options for box>]{<title>}
    <column one>
    \tcblower
    <column two>
\end{listingbox}

You can then say:

\begin{listingbox}*[width=.4\textwidth]{China}
  Alúmina\par Aluminio prim.\par Antimonio (P. M.)\par Arsénico blanco\par Barita\par Bismuto (P. M.)\par Cadmio\par Carbón\par Cobalto\par Cobre (P. R.)\par Cobre (P. F.)\par Fluorita\par Galio prim.\par Germanio metál.\par Oro (P. M.)\par Grafito\par Yeso\par Indio (P. R.)\par Hierro (mena)\par Arrabio\par Acero bruto\par Plomo (P. M.)\par Plomo (P. R.)\par  Magnesita\par Megnesio metál. prim.
  \tcblower Manganeso (mena)\par Mercurio\par Mica\par Molibdeno (P. M.)\par Níquel (P. R./P.F.)\par Perlita\par Roca fosfórica\par Óx. de tierras raras\par Sal\par Min. de estroncio\par Piritas\par Talco\par Estaño (P. M.)\par Estaño (P. F.)\par Tungsteno (P. M.)\par Vanadio (P. M.)\par Wollastonita\par Zinc (P. M.)\par Zinc (planchas)
\end{listingbox}%
\hskip 2mm
\begin{listingbox}[width=.275\textwidth]{EE.UU.}
Bentonita\par Tierra de batán\par Berilio\par Bromo\par Diatomita\par Caolín\par Gas natural\par Carb. de sodio natural\par Sulfuro (recuperado)\par Telurio metál.
\end{listingbox}

to produce:

list boxes in blue

Complete code:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
\DeclareTColorBox{listingbox}{ s O {} m }{%
  enhanced,
  title=#3,
  fonttitle=\bfseries,
  coltitle=white,
  top=10pt,
  bottom=10pt,
  left=10pt,
  right=10pt,
  boxsep=0pt,
  fontupper=\small,
  attach boxed title to top center={%
    yshift=-\tcboxedtitleheight/2,
    yshifttext=-\tcboxedtitleheight/2},
  boxed title style={%
    colframe=blue!70!black,
    colback=blue!70!black
  },
  colframe=blue!70!black,
  colback=blue!5!white,
  box align=top,
  nobeforeafter,
  IfBooleanTF={#1}{%
    sidebyside,
    sidebyside align=top,
    sidebyside gap=10pt,
    lower separated=false,
  }{},
  #2,
}
\begin{document}

\begin{listingbox}*[width=.4\textwidth]{China}
  Alúmina\par Aluminio prim.\par Antimonio (P. M.)\par Arsénico blanco\par Barita\par Bismuto (P. M.)\par Cadmio\par Carbón\par Cobalto\par Cobre (P. R.)\par Cobre (P. F.)\par Fluorita\par Galio prim.\par Germanio metál.\par Oro (P. M.)\par Grafito\par Yeso\par Indio (P. R.)\par Hierro (mena)\par Arrabio\par Acero bruto\par Plomo (P. M.)\par Plomo (P. R.)\par  Magnesita\par Megnesio metál. prim.
  \tcblower Manganeso (mena)\par Mercurio\par Mica\par Molibdeno (P. M.)\par Níquel (P. R./P.F.)\par Perlita\par Roca fosfórica\par Óx. de tierras raras\par Sal\par Min. de estroncio\par Piritas\par Talco\par Estaño (P. M.)\par Estaño (P. F.)\par Tungsteno (P. M.)\par Vanadio (P. M.)\par Wollastonita\par Zinc (P. M.)\par Zinc (planchas)
\end{listingbox}%
\hskip 2mm
\begin{listingbox}[width=.275\textwidth]{EE.UU.}
Bentonita\par Tierra de batán\par Berilio\par Bromo\par Diatomita\par Caolín\par Gas natural\par Carb. de sodio natural\par Sulfuro (recuperado)\par Telurio metál.
\end{listingbox}

\end{document}

EDIT

For many boxes arranged similarly to your sample image, you can use minipages to create vertical columns from several boxes:

many boxes

\documentclass[a4paper]{article}
\usepackage[scale=.85]{geometry}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
\DeclareTColorBox{listingbox}{ s O {} m }{%
  enhanced,
  title=#3,
  fonttitle=\bfseries,
  coltitle=white,
  top=10pt,
  bottom=10pt,
  left=10pt,
  right=10pt,
  boxsep=0pt,
  fontupper=\small,
  attach boxed title to top center={%
    yshift=-\tcboxedtitleheight/2,
    yshifttext=-\tcboxedtitleheight/2},
  boxed title style={%
    colframe=blue!70!black,
    colback=blue!70!black
  },
  colframe=blue!70!black,
  colback=blue!5!white,
  box align=top,
  nobeforeafter,
  halign lower=left,
  halign upper=left,
  IfBooleanTF={#1}{%
    sidebyside,
    sidebyside align=top,
    sidebyside gap=10pt,
    lower separated=false,
  }{},
  #2,
}
\begin{document}
\noindent
\begin{listingbox}*[width=.35\textwidth]{China}
  Alúmina\par Aluminio prim.\par Antimonio (P. M.)\par Arsénico blanco\par Barita\par Bismuto (P. M.)\par Cadmio\par Carbón\par Cobalto\par Cobre (P. R.)\par Cobre (P. F.)\par Fluorita\par Galio prim.\par Germanio metál.\par Oro (P. M.)\par Grafito\par Yeso\par Indio (P. R.)\par Hierro (mena)\par Arrabio\par Acero bruto\par Plomo (P. M.)\par Plomo (P. R.)\par  Magnesita\par Megnesio metál. prim.
  \tcblower Manganeso (mena)\par Mercurio\par Mica\par Molibdeno (P. M.)\par Níquel (P. R./P.F.)\par Perlita\par Roca fosfórica\par Óx. de tierras raras\par Sal\par Min. de estroncio\par Piritas\par Talco\par Estaño (P. M.)\par Estaño (P. F.)\par Tungsteno (P. M.)\par Vanadio (P. M.)\par Wollastonita\par Zinc (P. M.)\par Zinc (planchas)
\end{listingbox}%
\hskip 2mm
\begin{minipage}[t]{.25\textwidth}
  \begin{listingbox}[width=.975\linewidth]{EE.UU.}
    Bentonita\par Tierra de batán\par Berilio\par Bromo\par Diatomita\par Caolín\par Gas natural\par Carb. de sodio natural\par Sulfuro (recuperado)\par Telurio metál.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{EE.UU.}
    Bentonita\par Tierra de batán\par Berilio\par Bromo\par Diatomita\par Caolín\par Gas natural\par Carb. de sodio natural\par Sulfuro (recuperado)\par Telurio metál.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{EE.UU.}
    Bentonita\par Tierra de batán\par Berilio\par Bromo\par Diatomita\par Caolín\par Gas natural\par Carb. de sodio natural\par Sulfuro (recuperado)\par Telurio metál.
  \end{listingbox}
\end{minipage}%
\hskip 2mm
\begin{minipage}[t]{.175\textwidth}
  \begin{listingbox}[width=.975\linewidth]{Chile}
    Something\par Something\par Something else\par One last thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Australia}
    Something\par Something\par Something else\par One final thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Canada}
    Something\par Something\par One last thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Turkey}
    Something\par different.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Greenland}
    Something\par Another thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Iceland}
    Something\par Something\par Something else.
  \end{listingbox}\medskip
\end{minipage}%
\hskip 2mm
\begin{minipage}[t]{.175\textwidth}
  \begin{listingbox}[width=.975\linewidth]{Chile}
    Something\par Something\par Something else\par One last thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Australia}
    Something\par Something\par Something else\par One final thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Canada}
    Something\par Something\par One last thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Turkey}
    Something\par different.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Greenland}
    Something\par Another thing.
  \end{listingbox}\medskip

  \begin{listingbox}[width=.975\linewidth]{Iceland}
    Something\par Something\par Something else.
  \end{listingbox}\medskip
\end{minipage}
\end{document}
  • 1
    @Fernando If this solves the problem, don't forget to consider accepting the answer by clicking on the greyed-out check mark by the up/down vote thingy at the top left of the answer. (Hope that makes sense - it is not terribly obvious, if you ask me.) – cfr Oct 11 '15 at 21:10
  • Thank you very much cfr. I think the solution you say with listinbox is much better than using minipages. However the problem is that I have like ten boxes of different sizes, and I do not really know how to get an arrangement like this: s1.postimg.org/9icr840nj/Example.png using that code (I am sorry I am new in this so maybe it is easy but I haven´t been able to locate one box next or below another modifyig the code). Thank you very much for the help. – Fernando Oct 12 '15 at 22:05
  • 1
    @Fernando See edited answer for an example which arranges lots of the boxes using minipages to create vertical stacks. There are other ways to do this - this may not be the easiest, I'm not sure. But it is the way I'd probably do it just because I know this way ;). – cfr Oct 12 '15 at 22:36

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.