1

I am using a template given to me by the department. You can see the full template here.

I have used a package called tabularx, and in overleaf I get following error
overleaf tabularx error
I could not copy paste because many times doing Ctrl+C and Ctrl+V for error in overleaf I had cursor changing and I could not do a Ctrl+C , I could select the error by right click on touchpad and drag but when I do a right click to copy it did not give an option to copy to search in Google.

here the table code of latex thesis.tex file has following

\documentclass[twoside,mtp]{iiitg}

\usepackage{tabularx}
\usepackage{fancyhdr}
  \fancyhead{}
  \fancyhead[LO]{\slshape \rightmark}
  \fancyhead[RO,LE]{\textbf{\thepage}}
  \fancyhead[RE]{\slshape \leftmark}
  \fancyfoot{}
  \pagestyle{fancy}
  \renewcommand{\chaptermark}[1]{\markboth{\chaptername \ \thechapter \ \ #1}{}}
  \renewcommand{\sectionmark}[1]{\markright{\thesection \ \ #1}}
\clearemptydoublepage
\input{texfiles/chapter2}

and in chapter 2 I have added this table

    \begin{table}[htbp]
        \centering
        \begin{tabularx}{\textwidth}{| X | X | X |}
            \hline
            \heading{Alpha}     & \heading{Beta}     & \heading{Gamma}     \\ \hline
            0         & 2        & 4         \\ \hline
            1         & 3        & 5         \\ \hline
        \end{tabularx}

and as I could understand from the screenshot I posted above use of \heading is creating problems. In the github link of thesis template I gave above in thesis.tex they have not used \usepackage{tabularx} but I have added this line in tex file and then in the chapter2 I am doing this table manipulation. So in this case how can I get rid of these errors and warnings in this example.

11
  • 1
    If you look at the error message, you will see that the command \heading is not defined. Comment out the first line of your tabular and see if the document compiles.
    – Sveinung
    May 6 '20 at 12:05
  • 1
    Where you added is the wronag place. It should be loaded in document preamble. Where you define \heading?. Your code fragment work fine, if I define own \heading. So, problem is in part of your document hidden from us. Please (again) provide a MWE, which reproduce your problem.
    – Zarko
    May 6 '20 at 12:11
  • 1
    Where is defined heading? This is error which your receive from compiler.
    – Zarko
    May 6 '20 at 12:17
  • 1
    If you use thead from makcell instread your not defined heading your code work fine: \documentclass{article} \usepackage{makecell, tabularx} \begin{document} \begin{table}[ht] \begin{tabularx}{\textwidth}{| X | X | X |} \hline \thead{Alpha} & \thead{Beta} & \thead{Gamma} \\ \hline 0 & 2 & 4 \\ \hline 1 & 3 & 5 \\ \hline \end{tabularx} \end{table} \end{document}
    – Zarko
    May 6 '20 at 12:19
  • 1
    Error, which you mentioned in question title is not caused by your code fragment. SO please consider to change it since it is misleading. Your error is clearly reported: heading is not defined.
    – Zarko
    May 6 '20 at 12:32
1

You have two problems:

  • If you receive error as you stated in your question title, means that you not load the tabularx package.
  • If you leaded the tabularx package, than question title is misleading. Please, consider to change it accordingly.
  • Error, showed in question is clearly reported: \heading is not defined. This means, that you need to define it somewhere, the best place for this is document preamble that can be used anywhere in the document.
  • It is unknown, what you expect from this command, but I guessing that something like this:

enter image description here

which is produced by the following MWE:

\documentclass{article}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\normalsize}

\begin{document}
\begin{table}[ht]
\begin{tabularx}{\textwidth}{| X | X | X |}
\hline
\thead{Alpha}   & \thead{Beta}  & \thead{Gamma} \\ \hline
0               & 2             & 4             \\ \hline
1               & 3             & 5             \\ \hline
\end{tabularx}
\end{table}
\end{document}   

where thead command is define in the makecell package`.

Finally, a general tip: load only those packages which you really need. Define new commands as few as possible.

Addendum: regarding vertical lines in table: many people here (including me) prefer tables without vertical lines. To our opinions they looks nicer and more "professional":

enter image description here

Above table is produced by:

documentclass{article}
\usepackage{booktabs, makecell, tabularx}
\renewcommand\theadfont{\normalsize}
\renewcommand\theadgape{}

\begin{document}
\begin{table}[ht]
\begin{tabularx}{\textwidth}{ X X X }
    \toprule
\thead{Alpha}   & \thead{Beta}  & \thead{Gamma} \\ 
    \midrule
0               & 2             & 4             \\ 
1               & 3             & 5             \\ 
    \bottomrule
\end{tabularx}
\end{table}
\end{document}   
5
  • Thanks for your detailed answer this is exactly what I was looking. I changed the title of question as suggested.
    – koeradoera
    May 6 '20 at 13:01
  • I used exactly the same code as you mentioned but some how vertical lines did not appear. Here is a screenshot of how it appears imgur.com/b72NpwU and to make sure preamble I did what you mentioned this screenshot of preamble imgur.com/AtH6FtU . In case you want to see any thing more then here github.com/kiotie32/original-template you can see original template. I have just added the lines which in this discussion you wrote as answer. So ideally I should have had a table with vertical lines.
    – koeradoera
    May 6 '20 at 13:15
  • I see that your crystall ball is working well! +1
    – egreg
    May 6 '20 at 15:26
  • @egreg, thank you! Today I have time to polish it (crystal ball) , but who knows if this will be sufficient for tomorrow :-)
    – Zarko
    May 6 '20 at 19:45
  • @koeradoera,I'm not expert for Overleaf, however, i tested my MWE in it and result is the same as I show in my answer. Anyway, see addendum to my answer for table example without vertical lines.
    – Zarko
    May 6 '20 at 19:54

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.