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

SRel
  • 1,313
  • 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 04 '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 04 '20 at 19:42

2 Answers2

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}
Tobi
  • 56,353
  • 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 08 '20 at 01:37
  • @SRel: Seems like an incompatibility between collcell and longtable, see https://tex.stackexchange.com/q/243352/4918. If the linked question doesn’t help don’t hesitate to ask a new one ;-) – Tobi Feb 08 '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
Patrick
  • 31
  • 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 05 '20 at 06: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 05 '20 at 23:28
  • I tested yours also @Patrick and you solution also save me lots of times when changing column number :) – SRel Feb 08 '20 at 01:38
  • @ do you have an idea how I can change the fontsize of the x? Using \smallor fontsize runs in an error – SRel Feb 08 '20 at 02: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
  • You might find this link useful too. Seems like it could help you with your formatting. – Patrick Feb 11 '20 at 22:35