2

I am working on layoutin a huge table for my thesis. For this it would be great that the tabl is not just blank, it should contain all empty cells with dummy values like x It simply could do so by entering &x&x&x&x&x but everytime I changed my amount of columns I have to fill every row by hand with the exact amount of x&x&x&x which can be very fuzzy having 60+ rows.

Is there some easy step I can say at the beginning of my table like it is possible in tikz matrixwhere I can define empty cells = Valuexyz, so that all cells are filled with dummy values?

Just empty cells should be replaced. All with content should not.

MWE:

\documentclass[a4paper]{article} 
\usepackage{booktabs} 
\begin{document} 
\begin{tabular}{llllcccccccccccccccccccccccccccccccccccccccccccccccccccccccc}
\toprule
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
\bottomrule
\end{tabular}
\end{document}

My table look like this:

Current progress

2
  • Is a table with 60 columns really going to fit into a single page? Could you please add some background information on the actual contents of the cells?
    – leandriis
    Feb 4 '20 at 19:32
  • 1
    I am trying to do a conceptmatrix with just a single char in each cell, i will add a pciture to my original post
    – SRel
    Feb 4 '20 at 19:42
4

The following approach uses the cellcoll package to collect the cell content and then \IfEq of package xstring to test wether the cell is empty (then print -) or not (then print the cell content as is #1).

\documentclass{article}

\usepackage{xstring}
\usepackage{array,collcell}
\newcolumntype{C}{>{\collectcell\checkempty}c<{\endcollectcell}}
\def\checkempty#1{%
   \IfEq{#1}{}{-}{#1}%
}

\begin{document}
\begin{tabular}{CCC}
   &&X\\
   &&\\
   &X&\\
   O&X&\\
   X&&T\\
\end{tabular}
\end{document}
2
  • I don't know exactly why, however using the longtabularenvironemnt results in huge of errors i am not familliar with. however inside normal tabular this works perfectly
    – SRel
    Feb 8 '20 at 1:37
  • @SRel: Seems like an incompatibility between collcell and longtable, see tex.stackexchange.com/q/243352/4918. If the linked question doesn’t help don’t hesitate to ask a new one ;-)
    – Tobi
    Feb 8 '20 at 11:19
1

If you're after a method for easily changing the number of columns that your table has, this method should help. It works by using a loop to enter each &x that you have.

To change the number of columns that are in your table, simply adjust the \numcols parameter.

Table populated with 'x&'s

\documentclass[a4paper]{article} 
\usepackage{booktabs}

\newcounter{countA}%
\newcommand{\numcols}{20}

\newcommand{\repeatentry}[2]{%
    \def\myline{#1}%
    \setcounter{countA}{1}%
    \loop\ifnum\thecountA<#2%
        \stepcounter{countA}%
        \edef\myline{\myline & #1}%
    \repeat%
    \myline{}%
}

\begin{document} 
\begin{tabular}{|*{\numcols}{c|}}
    \toprule
    \repeatentry{x}{\numcols}\\
    \repeatentry{x}{\numcols}\\
    \repeatentry{x}{\numcols}\\
    \bottomrule
\end{tabular}
\end{document}

EDIT:

In order to allow formatting to enter the \repeatentry command, the following change must be made. This is done to protect the expansions of the formatting when \edef adds another column. This is preferred over using \noexpand, as the nesting of \edef requires a similar nesting of \noexpand.

\makeatletter
\newcommand{\repeatentry}[2]{%
    \def\myline{#1}%
    \setcounter{countA}{1}%
    \loop\ifnum\thecountA<#2%
        \stepcounter{countA}%
        \protected@edef\myline{\myline & #1}%
    \repeat%
    \myline{}%
}
\makeatother
6
  • 1
    If I understood the question correctly not all cells should be filled with x, but only the ones without a manual entry … shouldn’t it?
    – Tobi
    Feb 5 '20 at 6:32
  • 1
    I do agree, and I like your solution. However, the OP also seemed to struggle with having the rows match up when he changes the number of columns. I thought this might help?
    – Patrick
    Feb 5 '20 at 23:28
  • I tested yours also @Patrick and you solution also save me lots of times when changing column number :)
    – SRel
    Feb 8 '20 at 1:38
  • @ do you have an idea how I can change the fontsize of the x? Using \smallor fontsize runs in an error
    – SRel
    Feb 8 '20 at 2:01
  • Hi @SRel, that error occurs due to the nested edef expanding the \small formatting rather than the columns. I'll post an edit to show the modification necessary to allow for any formatting.
    – Patrick
    Feb 11 '20 at 22:33

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.