1

have a table like below with a custom width, but i can not run it, any ideas? many thanks in advance

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[ht]
    \centering
    \begin{tabular}{p{0.015\textwidth}|R{0.37\textwidth}|R{0.12\textwidth}|R{0.08\textwidth}|R{0.02\textwidth}|p{0.35\textwidth}|}
        \hline
        & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species \\ 
        \hline
        1 & 5 & 4 & 1 & 0 & setosa \\ 
        2 & 5 & 3 & 1 & 0 & setosa \\ 
        3 & 5 & 3 & 1 & 0 & setosa \\ 
        4 & 5 & 3 & 2 & 0 & setosa \\ 
        5 & 5 & 4 & 1 & 0 & setosa \\ 
        6 & 5 & 4 & 2 & 0 & setosa \\ 
        \hline
    \end{tabular}
\end{table}
\end{document}
3
  • 3
    R and C are not standard column types.
    – Joseph Wright
    Apr 29 '20 at 8:55
  • how can i set the width of the table, properly ? Apr 29 '20 at 8:58
  • 2
    @SeymaKalay - For suggestions on how to set the width of a tabular-like environment to a specific value (say, 1\textwidth), please see the posting How to force a table into page width? The two leading candidates are the tabularx and tabular* environments.
    – Mico
    Apr 29 '20 at 9:07
1

You don't need to specify the column widths. Also, you can avoid spreading too much the table by grouping the columns.

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}[htp]
\centering

\begin{tabular}{
  @{}
  r  % number
  ccccc
  @{}
}
\toprule
& \multicolumn{2}{c}{Sepal} & \multicolumn{2}{c}{Petal} & Species \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& Length & Width & Length & Width & \\ 
\midrule
1 & 5 & 4 & 1 & 0 & setosa \\ 
2 & 5 & 3 & 1 & 0 & setosa \\ 
3 & 5 & 3 & 1 & 0 & setosa \\ 
4 & 5 & 3 & 2 & 0 & setosa \\ 
5 & 5 & 4 & 1 & 0 & setosa \\ 
6 & 5 & 4 & 2 & 0 & setosa \\ 
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

1

You have not defined R column type. If you want it to do want I guess you mean then you can use wr (with a relatively recent version of the array package) But this is forcing the column widths to values that are inappropriate for the column contents, and forcing the total table width to not fit the page. Just using a natural widths makes the table easier to read, or better remove the vertical lines and use booktabs package.

enter image description here

\documentclass{article}
\usepackage{array,booktabs}
\begin{document}
\begin{table}[ht]
    \centering
    \begin{tabular}{wl{0.015\textwidth}|wr{0.37\textwidth}|wr{0.12\textwidth}|wr{0.08\textwidth}|wr{0.02\textwidth}|wr{0.35\textwidth}|}
        \hline
        & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species \\ 
        \hline
        1 & 5 & 4 & 1 & 0 & setosa \\ 
        2 & 5 & 3 & 1 & 0 & setosa \\ 
        3 & 5 & 3 & 1 & 0 & setosa \\ 
        4 & 5 & 3 & 2 & 0 & setosa \\ 
        5 & 5 & 4 & 1 & 0 & setosa \\ 
        6 & 5 & 4 & 2 & 0 & setosa \\ 
        \hline
    \end{tabular}
\end{table}


\begin{table}[ht]
    \centering
    \begin{tabular}{r|r|r|r|r|l|}
        \hline
        & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species \\ 
        \hline
        1 & 5 & 4 & 1 & 0 & setosa \\ 
        2 & 5 & 3 & 1 & 0 & setosa \\ 
        3 & 5 & 3 & 1 & 0 & setosa \\ 
        4 & 5 & 3 & 2 & 0 & setosa \\ 
        5 & 5 & 4 & 1 & 0 & setosa \\ 
        6 & 5 & 4 & 2 & 0 & setosa \\ 
        \hline
    \end{tabular}
\end{table}


\begin{table}[ht]
    \centering
    \begin{tabular}{cccccl}
        \toprule
        & Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species \\ 
        \midrule
        1 & 5 & 4 & 1 & 0 & setosa \\ 
        2 & 5 & 3 & 1 & 0 & setosa \\ 
        3 & 5 & 3 & 1 & 0 & setosa \\ 
        4 & 5 & 3 & 2 & 0 & setosa \\ 
        5 & 5 & 4 & 1 & 0 & setosa \\ 
        6 & 5 & 4 & 2 & 0 & setosa \\ 
        \bottomrule
    \end{tabular}
\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.