0

I have the following table which I want it to be in the centre of a two column document. But I want to table horizontal lines to be reduced so that they are aligned with the table content width and not the page width. Here is a screen shot and the script.

enter image description here

The script:

\documentclass[letterpaper,twocolumn,10pt]{article}

%table
\usepackage{array,tabularx}
\usepackage{multirow,booktabs} %for the table
\usepackage{pifont}% cross and match marks. http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%


\begin{document}

\begin{table*} [t!] \centering
  \centering

  \label{tab:table1}

\begin{tabularx}{\textwidth}{lcccc} %{\columnwidth}{cccccc}
    \toprule
                                      & col1  & col2  & col3  \\ %& Secure key  & \textit{VRF} Waiting Time\\
    \midrule
      row1                & \cmark             & \cmark        & \cmark        \\   %& \\
      row2                       & \cmark             & \cmark         & \cmark        \\  %& \\
      row3  &                 &                & \cmark        \\   %&    \\   

    %prettifies & the & content \\

    \bottomrule
  \end{tabularx}

\caption{table.}
\end{table*}

\end{document}
  • 1
    the lines are just over long as the input is in error tabularx has to have X columns, but here just use \begin{tabular}{lcccc} – David Carlisle Dec 9 '16 at 13:15
  • 1
    @DavidCarlisle Another example of tabularx misuse :) – CarLaTeX Dec 9 '16 at 13:27
  • 2
    @CarLaTeX I blame the author of the package – David Carlisle Dec 9 '16 at 13:34
  • 1
    @DavidCarlisle Yes, it must be package author's fault! Hahahaha – CarLaTeX Dec 9 '16 at 13:36
  • To generate quickly a complex LaTeX tables online, you can use the generator tablesgenerator.com or a plugin for Ex­cel at link ctan.org/pkg/excel2latex without mistakes. – Sebastiano Dec 13 '16 at 10:01
2

Best solution: Do not use tabularx with \textwidth if you do not want this. Especially if you do not have X column tabularx cannot work (see manual).

Besides that you should:

  1. Do not use \centering twice.
  2. Use \label after \caption.

Here's a working version:

\documentclass[letterpaper,twocolumn,10pt]{article}

\usepackage{array}
\usepackage{multirow,booktabs} %for the table
\usepackage{pifont}% cross and match marks. http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%

\begin{document}

\begin{table*}[t!]
  \centering

\begin{tabular}{lcccc}
    \toprule
                                      & col1  & col2  & col3  \\ 
    \midrule
      row1                & \cmark             & \cmark        & \cmark        \\  
      row2                       & \cmark             & \cmark         & \cmark        \\ 
      row3  &                 &                & \cmark        \\

    \bottomrule
  \end{tabular}

\caption{table.}\label{tab:table1}
\end{table*}

\end{document}

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.