# Longtable, contained tikz, padding, custom columns, and an alignment issue

My white whale. I can't for the life of me figure out what's going on with the margins caused by minipage existing in the column definition.

Given column type M extending c: I can change line 6 from >{ to >{% and suddenly the left padding disappears while keeping the right padding. If I add a % to the end of line 14 where minipage ends, then the padding on the right also disappears. This isn't how comments work...also, the tikz not aligning vertically in the minipage, which I thought I handled with \begin{minipage}[c]{#1}.

I can change line 11 from c to m{#1} and now the line 6 and 14 % doesn't have any effect..and the tikz is still not vertically centered (top indent exists). If I manually set the minipage to be the height of what's in the tikzpicture, 30pt, then there's a big margin up top. Then If I manually set the minipage height to be 34pt, the tikzpicture is vertically and horizontally centered on the minipage...

However, this doesn't solve my issue of making the minipage automatically adjust its height relative to its contents on any other table, or how to disregard that minimum padding at the top. It doesn't help that I can't seem to turn the height into a second variable passed to the column type M, either.

If I set the column at 67.5pt, then the "hbox too wide" appears on the first tikz. However, the tikz is supposed to be (15+37.5+15=67.5) points wide. The overflow from the brown box shows me that minipage seems to have its own margins as well.

The tikzpicture options are only there to experiment with getting this alignment take care of.

All I want is perfectly centered tikz next to perfectly centered math, with the a single minimum margin applied to all 8 cells equally. If it could be automated, even better. This seems above my level of knowledge right now...and entirely unreasonable that this can/has become so needlessly complex

\documentclass{article}
\usepackage{array,longtable,tikz,calc}
\setlength{\tabcolsep}{0mm}
\newcolumntype{M}[1]
{
>{
\noindent\begin{minipage}[c][][c]{#1}%\textwidth-1.5\arrayrulewidth-2\tabcolsep}
%\vspace{0pt}
\centering
}
c
<{
%\vspace{0pt}
\end{minipage}
}
}
\newcolumntype{A}[1]
{%
>{$} r <{$}
@{\extracolsep{0pt}}
>{${}} l <{$}
|}%
\begin{document}
\begin{longtable}{| M{68.5pt} | A |}% \setstretch{1.0}%q{0.38} |}
\hline
\noindent\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]%  ,baseline=(current bounding box.center)]
\draw [gray] (0,0) circle (15pt);
\filldraw [gray] (0,0) circle (1pt);
\draw [gray] (37.5pt,0) circle (15pt);
\filldraw [gray] (37.5pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& \underline{2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)}  &\geq  2r_f + R_1 r_f
\tabularnewline
\hline
\centering\begin{tikzpicture}[baseline=(current bounding box.south)]%[every node/.style={inner sep=0,outer sep=0}]
\draw [gray] (0,0) circle (15pt);
\filldraw [gray] (0,0) circle (1pt);
\draw [gray] (30pt,0) circle (15pt);
\filldraw [gray] (30pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)  &\leq   2r_f+\underline{R_1 r_f} \tabularnewline
\hline
\begin{tikzpicture} [baseline=(current bounding box.center)]
\draw [gray] (0,0) circle (15pt);
\filldraw [gray] (0,0) circle (1pt);
\draw [gray] (22.5pt,0) circle (15pt);
\filldraw [gray] (22.5pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)  &<   \underline{2r_f}+R_1 r_f \tabularnewline
\hline
\begin{tikzpicture} %[baseline=(current bounding box.center)]
\draw [gray] (0,0) circle (15pt);
\filldraw [gray] (0,0) circle (1pt);
\draw [gray] (11.25pt,0) circle (15pt);
\filldraw [gray] (11.25pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)  &<   \underline{2r_f}+R_1 r_f \tabularnewline
\hline
\end{longtable}
\end{document}
• A line ending is a space. Commenting it removes the space. This is how comments work .... – cfr Dec 6 '17 at 2:54
• I can't help but think there's an easier way to do whatever it is you're trying to do .... – cfr Dec 6 '17 at 2:57

i must confess, that i don't understand your question well. it is not clear, why you use longtable and so complicated definitions for used columns types. i suspect that you looking for something like this:

code for above table is simple (i left longtable in it):

\documentclass[12pt]{article}
\usepackage{array, makecell, longtable}
\setcellgapes{5pt}
\usepackage{tikz}
\usepackage{xfrac}

\begin{document}
\begingroup
\makegapedcells
\tikzset{every node/.style={inner sep=0,outer sep=0}}
\begin{longtable}{| c | >{$\displaystyle}c<{$} |}
\hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (37.5pt,0) circle (15pt);
\filldraw [gray]    (37.5pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& \underline{2r_c \sin \left(\sfrac{\pi}{n_k}\right)} \geq  2r_f + R_1 r_f  \tabularnewline
\hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (30pt,0) circle (15pt);
\filldraw [gray]    (30pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left(\sfrac{\pi}{n_k}\right) \leq  2r_f+\underline{R_1 r_f}    \tabularnewline
\hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (22.5pt,0) circle (15pt);
\filldraw [gray]    (22.5pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left(\sfrac{\pi}{n_k}\right) < \underline{2r_f}+R_1 r_f        \tabularnewline
\hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (11.25pt,0) circle (15pt);
\filldraw [gray]    (11.25pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left(\sfrac{\pi}{n_k}\right) <  \underline{2r_f + R_1 r_f}     \tabularnewline
\hline
\end{longtable}
\endgroup
\end{document}

edit:

• longtable is normally used when table is to long for one page. it enable continuation of table on the next page(s)
• with \begingroup and \endgroup the settings for the \longtable (\makegapedcells and \tikzset{every node/.style={inner sep=0,outer sep=0}}) are valid only for this table.
• since \tikzset{...} is before \longtable, it valid for all tikz pictures in \longtable
• tables and images are usually put in floats' environments table or figure respectively. this floats can move (float) in text. this meaning that their exact position in text is determined by algorithm in latex, which work hardly that document obtain the best possible looks. it also can contains setting valid only for this float (see mwe below)
• horizontal position of cells' contents depends on column's type (standard are c, l and r for centered, left align and right align respectively, p{...} for cells which can contain a "paragraph" of text)
• the vertical position depends on baseline of cells' contents. images has default baseline position at the theirs bottom.
• baseline position of tikzpicture can be changed with option baseline. with baseline=(current bounding box.base) is moved to the vertical center of image. with baseline=-3pt the image vertical center is mowed for 3pt below baseline in cell's row
• for better looking of math expressions i add package xfrac and use its \sfrac macro for typing fractions in sinus function argument.
• command \makegapedcells from package makcell add vertical space determined by macro \setcellgapes{<length>} above and below cells' contents

considering the aforementioned, the mwe is:

\documentclass[12pt]{article}
\usepackage{array, makecell}  % <--- changed
\setcellgapes{5pt}
\usepackage{tikz}
\usepackage{xfrac}

\begin{document}
\makegapedcells
\tikzset{every node/.style={inner sep=0,outer sep=0}}
\begin{tabular}{| c | >{$}c<{$} |} % <--- changed
\hline
\begin{tikzpicture}[baseline=-3pt]  % <--- changed
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (37.5pt,0) circle (15pt);
\filldraw [gray]    (37.5pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& \underline{2r_c \sin \left(\sfrac{\pi}{n_k}\right)} \geq  2r_f + R_1 r_f  \tabularnewline
\hline
\begin{tikzpicture}[baseline=-3pt] % <--- changed
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (30pt,0) circle (15pt);
\filldraw [gray]    (30pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left(\sfrac{\pi}{n_k}\right) \leq  2r_f+\underline{R_1 r_f}    \tabularnewline
\hline
\begin{tikzpicture}[baseline=-3pt] % <--- changed
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (22.5pt,0) circle (15pt);
\filldraw [gray]    (22.5pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left(\sfrac{\pi}{n_k}\right) < \underline{2r_f}+R_1 r_f        \tabularnewline
\hline
\begin{tikzpicture}[baseline=-3pt] % <--- changed
\draw [gray]        (0,0) circle (15pt);
\filldraw [gray]    (0,0) circle (1pt);
\draw [gray]        (11.25pt,0) circle (15pt);
\filldraw [gray]    (11.25pt,0) circle (1pt);
\draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
& 2r_c \sin \left(\sfrac{\pi}{n_k}\right) <  \underline{2r_f + R_1 r_f}     \tabularnewline
\hline