2

I have these three graphics all in one line. Now I would like to have 3 columns with their respective data aligned underneath them (the alignment underneath the graphics does not really matter).

This is what I have:

\begin{multicols}{3}
\begin{enumerate}
\item (1)(2)(3) 
\item(1,2)(3) 
\item(1,3)(2) 
\item(2,3)(1) 
\item(1, 2, 3) 
\item(1, 3, 2)
\item(1)(2)(3)(4)
\item(1,3)(2)(4)
\end{enumerate}
\end{multicols}

How can I specify which column each \item goes into? For example, I want column 1 to contain everything except the last 2 \items and column 2 to contain the last 2 \items. (I did not include all the data in this post)

How can I format this data into three columns and specify which column they shall be placed in?

3
  • Perhaps the approach you are suggesting right now it's not the best one (specially if there's no particular order for the items of each column); perhaps you could use three side-by-side minipages and place one enumearte environment in each one of the minipages? Oct 7, 2012 at 19:13
  • I think it would be helpful if you provided some example as I am not clear on what you are trying to accomplish. If you could show what you want instead of describing it that would probably greatly clarify things. Oct 7, 2012 at 19:29
  • Was my answer below of any help, or did I totally misunderstand the question? Nov 1, 2012 at 7:02

1 Answer 1

2

It seems that this is another case (see References below for the earlier case) where the most important thing to figure out really is exactly how do you want to specify which items you want printed. So, here is one way where you can specify which rows of the data end up in each of the columns.

  1. Define the enumerated list in a macro so that it can be reused. In this you call \MyItem{} and pass in the parameter as the data:

    \begin{enumerate}%
        \MyItem{(1)(2)(3)}
        \MyItem{(1,2)(3)}
        \MyItem{(1,3)(2)}
        \MyItem{(2,3)(1)}
        \MyItem{(1, 2, 3)}
        \MyItem{(1, 3, 2)}
        \MyItem{(1)(2)(3)(4)}
        \MyItem{(1,3)(2)(4)}
    \end{enumerate}%
    

    This is part of the definition of the macro \MyEnumeratedList which has some initialization before this list.

  2. Now wherever you want to use this enumerated list, you simply specify which rows you actually want printed. So if you only want rows 2, 5 and 7 to be printed, you say:

    \MyEnumeratedList{2,5,7}
    

Any row not specified in this list is not printed.

So, with the data provided, I have printed the rows as specified in the question. Column 3 was not specified so I chose rows 2, 5, and 7 for that column:

enter image description here

Notes:

  • I assumed that the list was to be numbered consecutively from 1 for each of the columns. If this is not desired using another counter to number then would preserve the numbering of the items across the three columns.
  • I used three minipages to display the three columns, as suggested by Gonzalo Medina in the comments. The multicols approach is not the way to achieve the desired result.

  • There is an assumption here that at least one row will be printed in each column. Otherwise you will end up with the error message:

    LaTeX Error: Something's wrong--perhaps a missing \item.

    This could occur if you provide much larger numbers than the total number of rows.

Further Enchantments:

  • Handle the case where none of the rows are printed.
  • Provide for greater flexibility in how the rows are to be printed. For example a better way to have specified the first column in the example provided would have been:

    \MyEnumeratedList{1,...,6}
    

References:

  • Another answer where it the main problem was really to figure out how to specify what you want: automatically insert data in a complex table.

    So for these type of questions it would be helpful if the person asking the question considered first: How do I want to specify what I want?

Code:

\documentclass{article}
\usepackage{xstring}

\newcounter{RowCounter}
\newcommand*{\ListOfRowsToDisplay}{}%
\newcommand*{\MyItem}[1]{%
    % #1 = comma separated list of which rows to show
    % #2 = item data
    \stepcounter{RowCounter}%
    % Add extra commas on what we are searching for and what we are searching in.
    % Hence, to check if the number (for example), six is in the string we
    % search for ",6,".  This will prevent the returning of a false positive
    % when the number 6 is not in the sting, but the digit 6 is used as part of a
    % number.  Say the search string is "23,25,26,27", now searching for ",6,"
    % will result in not found, but searching for "6" would have resulted in the
    % string being found.
    \StrPosition{\ListOfRowsToDisplay}{,\arabic{RowCounter},}[\PositionInString]
    \IfEq{\PositionInString}{0}{%
        % This row number is not to be printed and we keep movin on
    }{%
        % This is a row that needs to be printed
        \item #1
    }%
}%
\newcommand*{\MyEnumeratedList}[1]{%
    % #1 = comma separated list of which rows to show
    \setcounter{RowCounter}{0}% reset as we are starting over
    % Save the list of rows globally so to make the enumerated list easier to read
    \xdef\ListOfRowsToDisplay{,#1,}%
    \begin{enumerate}%
        \MyItem{(1)(2)(3)}
        \MyItem{(1,2)(3)}
        \MyItem{(1,3)(2)}
        \MyItem{(2,3)(1)}
        \MyItem{(1, 2, 3)}
        \MyItem{(1, 3, 2)}
        \MyItem{(1)(2)(3)(4)}
        \MyItem{(1,3)(2)(4)}
    \end{enumerate}%
}%

\begin{document}
\begin{minipage}{0.30\linewidth}%
    \MyEnumeratedList{1,2,3,4,5,6}
\end{minipage}%
\begin{minipage}{0.30\linewidth}%
    \MyEnumeratedList{7,8}
\end{minipage}%
\begin{minipage}{0.30\linewidth}%
    \MyEnumeratedList{2,5,7}
\end{minipage}%

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .