2

I am trying to learn Latex and it is really driving me nuts...

I would like to remove any unecessary whitespace when using multicolumn (whitespace before, and the heading which i don't need in this case) Here is an example :

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\textsc{Hi}
\begin{table}[ht]
\begin{tabular}{ccc}
    \hline
    \multicolumn{2}{c}{}\\% i removed the heading but it creates unecessary whitespace
    X&X&X\\
    X&X&X\\
    \hline
\end{tabular}
\label{tab:multicol}
\end{table}

\end{document}

How to make the "Hi"as close as possible to the row with the X's? I am having a very hard time figuring it out..Please help! Thanks a lot!!

12
  • Welcome to TeX.SX! The most obvious thing I can suggest: comment the multicolumn entirely (provided you don't really need it). Aug 23, 2017 at 23:28
  • Never mind - tested it and the whitespace is still there. Let me check another way... Aug 23, 2017 at 23:32
  • How? I obviously already tried to remove the empty {} for the heading but all it does is to take the first "X" as a heading Aug 23, 2017 at 23:32
  • No worries - I was referring to something like this: % \multicolumn{...}. But I have tested it, and it doesn't work as expected. Aug 23, 2017 at 23:33
  • 1
    your approach and expectation are wrong. (i) floats -- in your case table always (deliberately) add some vertical space before and after float content. remove this space is against nice typography provided by latex(ii) have a label in float without caption is nonsense, since label not referee float but caption (which is missing), (iii) it is not clear what you mean with heading. if you mean caption of table? then put\caption{ ... table title ...} before tabular, (iv) etc. you should clarify what is your problem.
    – Zarko
    Aug 23, 2017 at 23:53

1 Answer 1

4

Well, if you need no floating table you can omit environment table (but then you also loose the floating possibility) in your code to make the "Hi" as close as possible to the row with the X's.

For a better typography environment table adds space before and after an floating table.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\textsc{Hi}

%\begin{table}[ht]
\begin{tabular}{ccc}
    \hline
%   \multicolumn{2}{c}{title}\\% i removed the heading but it creates unecessary whitespace
    X&X&X\\
    X&X&X\\
    \hline
\end{tabular}
\label{tab:multicol}
%\end{table}

\end{document}

with the result:

enter image description here

From a typographical view I do not recommend it ...

EDIT:

I recommend to use environment table. Please test the following code

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{blindtext} % to create dummy text

\begin{document}

\blindtext % to create a short dummy text
\textsc{Hi}

%\begin{table}[ht]
\begin{tabular}{ccc}
    \hline
%   \multicolumn{2}{c}{title}\\% i removed the heading but it creates unecessary whitespace
    X&X&X\\
    X&X&X\\
    \hline
\end{tabular}
\label{tab:multicol}
%\end{table}

\blindtext % to create a short dummy text

\begin{table}[ht]
\begin{tabular}{ccc}
    \hline
    X&X&X\\
    X&X&X\\
    \hline
\end{tabular}
\end{table}

\blindtext

\end{document}

with the result:

enter image description here

4
  • Wow ok i didn't think it would be that simple, thanks a lot!! Aug 23, 2017 at 23:54
  • What do you recommand then? Aug 24, 2017 at 0:00
  • @Zarko thank you for reminding me I just started to learn Latex, and for pointing out two mistakes in my code. if for you i am on a "very wrong way" because i did use \textsc instead of \lipsum[1] just for the purpose of the example and knowing i am a beginner, i really don't think so and thanks for the good welcoming here! Aug 24, 2017 at 0:29
  • sorry, you not catch the point. i'm not offend you, contrary, so no place for sarcasm here.
    – Zarko
    Aug 24, 2017 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .