7

Table problem here.

I want |c|c| to work, but it won't, and I cannot find the way to get what I want.

Can someone provide some insight, and maybe a link to the page (not to tabularx documentation since it hasn't helped).

table problem

code:

\documentclass[12pt]{article}
\usepackage{lipsum,wrapfig,graphicx,scrextend,sectsty,verbatim}
\usepackage{tikz,tkz-berge,amsmath,amsthm,amssymb,amsfonts}
\usepackage{tkz-graph,tabularx,adjustbox,enumerate,titlesec}
\usepackage[margin=1in]{geometry} 
\usepackage[latin1]{inputenc}
%commands for the tree packages below
\usetikzlibrary{trees,fit,shapes,arrows,calc, patterns}
\begin{document}
  \begin{table}
  \centering
  \begin{tabularx}{\linewidth}{ |c|X| }
  \hline
    \begin{tabular}[c]{@{}c@{}}
    \begin{tikzpicture}[baseline=(current bounding box.center),scale=2]
        \GraphInit[vstyle=Classic]
        \SetUpVertex[Lpos=-90]
        \tikzset{VertexStyle/.style = {shape=circle, fill=black, minimum size=3pt,inner sep=0pt}
            }
            \Vertex[x=0,y=0]{S$_0$}
            \Vertex[x=1,y=-.5]{dS$_0$}
            \Vertex[x=1,y=0]{mS$_0$}
            \Vertex[x=1,y=.5]{uS$_0$}
            \Vertex[x=0,y=-1]{t=0}
            \Vertex[x=1,y=-1]{t=1}
                \Edge[label = $\widetilde{p}_1$,color=red](S$_0$)(uS$_0$) 
                \Edges[label = $\widetilde{p}_2$,color=yellow](S$_0$,mS$_0$)
                \Edges[label = $\widetilde{p}_3$,color=green](S$_0$,dS$_0$)
                \Edges[label = $1+r$](t=0,t=1)
        \end{tikzpicture}
    \end{tabular}
  &
    \begin{enumerate}[I]
        \item. $m < d < 1+r < u$
        \item. $d < m < 1+r < u$
        \item. $d < 1+r < m < u$
        \item. $d < 1+r < u < m$
     \end{enumerate}\\\hline
  \end{tabularx}
 \end{table}
\end{document}
berkus
  • 1,168
ctde
  • 166
  • why do you have extra tabulars inside tabularx ? – percusse Jul 14 '17 at 07:09
  • It won't work otherwise. I've found it in another thread. I believe it it has to do with treating the data as a collection, otherwise using "\" sends the second column (Right) to the first column (left) – ctde Jul 14 '17 at 07:17
  • 2
    there are uses of nested tables but the one here, replacing a c entry by a one-cell nested table with a c entry, is doing nothing at all. – David Carlisle Jul 14 '17 at 07:46

3 Answers3

8

I am not sure, how the desired result looks like. Maybe something like that:

enter image description here

If you want to use |c|c| as column declaration fot the table, the environment enumerate must be used in a box like \parbox or minipage with a given width. Or you can use environment varwidth. Additionally I have used package enumitem to format the items in the enumeration.

\documentclass[12pt]{article}
\usepackage{tkz-graph}

\usepackage{varwidth}
\usepackage{enumitem}

\begin{document}
\begin{table}
  \centering
  \begin{tabular}{|c|c|}
  \hline
    \begin{tikzpicture}[baseline=(current bounding box.center),scale=2]
      \GraphInit[vstyle=Classic]
      \SetUpVertex[Lpos=-90]
      \tikzset{VertexStyle/.style = {shape=circle, fill=black, minimum size=3pt,inner sep=0pt}}
      \Vertex[x=0,y=0]{S$_0$}
      \Vertex[x=1,y=-.5]{dS$_0$}
      \Vertex[x=1,y=0]{mS$_0$}
      \Vertex[x=1,y=.5]{uS$_0$}
      \Vertex[x=0,y=-1]{t=0}
      \Vertex[x=1,y=-1]{t=1}
      \Edge[label = $\widetilde{p}_1$,color=red](S$_0$)(uS$_0$) 
      \Edges[label = $\widetilde{p}_2$,color=yellow](S$_0$,mS$_0$)
      \Edges[label = $\widetilde{p}_3$,color=green](S$_0$,dS$_0$)
      \Edges[label = $1+r$](t=0,t=1)
      \path(current bounding box.north)--++(0,2pt);% enlarge the height of the picture
    \end{tikzpicture}
  &
    \begin{varwidth}[c]{.6\linewidth}
      \begin{enumerate}[label={\Roman*.}]
          \item $m < d < 1+r < u$
          \item $d < m < 1+r < u$
          \item $d < 1+r < m < u$
          \item $d < 1+r < u < m$
       \end{enumerate}
     \end{varwidth}\\
  \hline
  \end{tabular}
\end{table}
\end{document}
esdd
  • 85,675
  • is it possible to make no borders? And thank you so very much! – ctde Jul 14 '17 at 16:20
  • To remove the top and the bottom border remove the \hline commands. For the left and right border change |c|c| to c|c or maybe you want to use @{}c|c@{}. – esdd Jul 14 '17 at 19:05
5

There are two things that cause extra space: one is the initial space introduced by itemize which you can remove by \@minipagetrue. and the other one is the baseline option you have in the TikZ picture. For the borders remove | and \hlines.

And you don't need extra tabular inside the tabularx environment.

Here is a hand tweaked version :

\documentclass[12pt]{article}
\usepackage{tkz-berge,amsmath,amsthm,amssymb,amsfonts,tkz-graph,tabularx,enumerate}
\usepackage[margin=1in]{geometry} 
\usepackage[latin1]{inputenc}
%commands for the tree packages below
\usetikzlibrary{trees,fit,shapes,arrows,calc, patterns}

\begin{document}
  \begin{table}
  \centering
  \begin{tabularx}{\linewidth}{ |c|>{\csname @minipagetrue\endcsname}X| }
  \hline
    \begin{tikzpicture}[scale=2,baseline={([yshift=1.5cm]current bounding box.center)}]
        \GraphInit[vstyle=Classic]
        \SetUpVertex[Lpos=-90]
        \tikzset{VertexStyle/.style = {shape=circle, fill=black, minimum size=3pt,inner sep=0pt}}
            \Vertex[x=0,y=0]{S$_0$}
            \Vertex[x=1,y=-.5]{dS$_0$}
            \Vertex[x=1,y=0]{mS$_0$}
            \Vertex[x=1,y=.5]{uS$_0$}
            \Vertex[x=0,y=-1]{t=0}
            \Vertex[x=1,y=-1]{t=1}
                \Edge[label = $\widetilde{p}_1$,color=red](S$_0$)(uS$_0$) 
                \Edges[label = $\widetilde{p}_2$,color=yellow](S$_0$,mS$_0$)
                \Edges[label = $\widetilde{p}_3$,color=green](S$_0$,dS$_0$)
                \Edges[label = $1+r$](t=0,t=1)
        \end{tikzpicture}
  &    \begin{enumerate}[I]
        \item. $m < d < 1+r < u$
        \item. $d < m < 1+r < u$
        \item. $d < 1+r < m < u$
        \item. $d < 1+r < u < m$
     \end{enumerate}\\\hline
  \end{tabularx}
 \end{table}
\end{document}

enter image description here

percusse
  • 157,807
4

I had a similar issue before. I my case I had some Tikz graphics within the table. I found that placing the Tikz figures as PDFs simplifies the problem a lot. Maybe you can also place the figure as a PDF.

Below is a sample that I have.

\documentclass[]{article}
\usepackage[a4paper]{geometry}
\usepackage{array}
\usepackage{amsmath}
\usepackage{upgreek}
\usepackage{caption}
\usepackage{graphicx}


\providecommand{\tabularnewline}{\\}
\captionsetup[table]{skip=10pt}
\setlength{\tabcolsep}{2pt}


\begin{document}
\begin{table}
    \centering{}\caption{\label{tab:SummMass}A Summary}
    \begin{tabular}{|>{\centering}m{6.2cm}|>{\centering}m{4cm}|>{\centering}m{4cm}|}
        \hline 
        \smallskip{}
        \textbf{Normalization Procedure} & \smallskip{}
        \textbf{Generalized Mass} & \smallskip{}
        \textbf{Effective Mass}\tabularnewline
        \hline 
        \noindent \includegraphics[width=6cm]
        {../Progress/EffMass/Paper/2017-05-20/figures/fig05a} &
        $\begin{aligned}\bar{m} &
        =\boldsymbol{\uppsi}^{\text{T}}\mathbf{M}\mathbf{\boldsymbol{\uppsi}}\\
        & =\sum_{j=1}^{n}\left(\psi_{j}\right)^{2}m_{j}
        \end{aligned}
        $ & $
        \begin{aligned}m_{i}^{\text{eff}} &
        =\frac{\bar{m}}{\left(\psi_{i}\right)^{2}}\end{aligned}
        $\tabularnewline
        \hline 
        \includegraphics[width=6cm]{../Progress/EffMass/Paper/2017-05-20/figures/fig05b} &
        $\begin{aligned}\bar{m}_{\text{D}} &
        =\boldsymbol{\uppsi}_{\text{D}}^{\text{T}}\mathbf{M}\mathbf{\boldsymbol{\uppsi}}_{\text{D}}\\
        & =\sum_{j=1}^{n}\left(\psi_{\text{D},j}\right)^{2}m_{j}
        \end{aligned}
        $ & $\begin{aligned}m_{i}^{\text{eff}} &
        =\frac{\bar{m}_{\text{D}}}{\left(\psi_{\text{D},i}\right)^{2}}\end{aligned}
        $\tabularnewline
        \hline 
    \end{tabular}
\end{table}
\end{document}

enter image description here

berkus
  • 1,168