1

I'm trying to center a table of images; 2 images per table row. Right now the code I have is ugly, and doesn't center on the document. I've tried using \begin{center} and \centering without any luck.

Also The way I created it, it currently creates a new table for every line. It's not ideal, but it the best I came up with so far. This is because I need to alternate text and images (for a caption effect, when I try to use the \caption I can't get the 2 column effect or the caption centers without the image and it's ugly)

Is there a way I can accomplish this considering there are about 100 images?

\begin{document}
stuff
stuff
stuff
\begin{center}
stuff that centers
stuff that centers
\figureLoop{pic(}{).jpg}     %Doesn't center :(
stuff that centers
\end{center}
\end{document}

The first parameter is the front half of file name (separated by a number that increases in the loop) and the 2nd part is the rest of the file name.

\newcommand{\figureLoop}[2]
  {   
  % Condition to loop; intitialized to true.
  \bool_set_true:N \runWhileLoop        
  % Place holders
  \int_zero:N \counter
\tmp=0
\Counter = \counter   

  % Run while condition is true
  \bool_while_do:Nn {\runWhileLoop}
  { 
        % Increment the counter   
    \int_incr:N \counter
    \Counter = \counter   
        % Create file name from the counter
    \edef\fileName{#1\int_use:N\counter#2}
        % Increment for the 2nd column
    \int_incr:N \counter
        % Define the 2nd column figures/number
    \edef\filename{#1\int_use:N\counter#2}      
        % Check if the file exists
    \file_if_exist:nTF {\fileName}
    {
            % Check to see if the 2nd column file exists/is necessary
        \file_if_exist:nTF {\filename}
        {
                \begin{table}[!htbp] 
                \begin{tabular}{c c}
                    \includegraphics[width=3.5cm]{\fileName} & \includegraphics[width=3.5cm]{\filename} \\
                    Image \number\Counter & Image \number\counter \\
                \end{tabular}
                \end{table}
        }{
                % If there's an odd number of photos
                \begin{table}[!htbp] 
                \begin{tabular}{c}
                    \includegraphics[width=3.5cm]{\fileName} \\
                    Image \number\Counter \\
                \end{tabular}
                \end{table}
        }   

        \advance\tmp by 1
        \ifnum\tmp=4
            \newpage
            \tmp=0
        \fi
    }{
        % there is no file with the given name
        % break the loop
        \bool_set_false:N \runWhileLoop
    }
  }
}

And this is what I currently get. This is the idea I want but centered completely. Any advice would be helpful, but I'd prefer something that has as little modification as possible.

Ugly format

0

1 Answer 1

4

Please always post complete documents not fragments but...

Since you are not using caption and don't want the things to float just don't use

 \begin{table}

 \end{table}

then the tabular will centre. If you do use table you need \centering inside the table as floats reset the paragraph parameters

3
  • I see, that makes sense. Thanks for the advice, I took out the \table and it looks a lot better. It's still not exactly centered, but there's likely some extra space that I put in by mistake.
    – mhag
    May 19, 2014 at 17:06
  • UPDATE: Found that \centerline works the best at least for my mess. Once I removed the table everything improved. Thanks again.
    – mhag
    May 19, 2014 at 17:14
  • @mhag \centerline isn't really a latex command (it got left on from plain tex) it's best not to use it ever in latex. May 19, 2014 at 17:26

You must log in to answer this question.

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