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!!

  • Welcome to TeX.SX! The most obvious thing I can suggest: comment the multicolumn entirely (provided you don't really need it). – logo_writer Aug 23 '17 at 23:28
  • Never mind - tested it and the whitespace is still there. Let me check another way... – logo_writer Aug 23 '17 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 – Jihane Sbaytti Aug 23 '17 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. – logo_writer Aug 23 '17 at 23:33
  • No problem, any other suggestion? – Jihane Sbaytti Aug 23 '17 at 23:35
  • Try putting \vspace*{-\baselineskip} before the \begin{table}, as per this answer. If it works for you, I can put it as an answer. – logo_writer Aug 23 '17 at 23:40
  • correct syntax of the firs line of the your table is: \multicolumn{2}{c}{} &. since this row is empty, just remove it. – Zarko Aug 23 '17 at 23:43
  • It removes the whitespace just before the tabular but not the heading of the multi-column, – Jihane Sbaytti Aug 23 '17 at 23:44
  • @Zarko as i said before all it does is to take the first "X" as a heading – Jihane Sbaytti Aug 23 '17 at 23:46
  • 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 '17 at 23:53
  • @Zarko why commands like \parskip and \vspace then exists? I think you're a big fan of latex which i understands it's beautiful but what you don't understand is first i am newbie and second it should have the possibility to change things like that, even if you think it is already good enough. I don't understand why you think it is nonsense to want to draw multi columns without any caption? i always did that irl why wouldn't it be possible in latex? – Jihane Sbaytti Aug 24 '17 at 00:09
  • @JihaneSbaytti, mentioned command has own purposes (\parskip for global settings of vertical space between paragraphs, \vspace mostly for defining vertical spaces at defining of new environments and rarely for what you insinuate). if the context of your problem be clear to me, i would glad to help you. caption: it is nonsense has label in float without caption. you can have table without caption, but what you will do if the table will float on the next page? As novice i suggest to read some introduction information about latex, for example https://tobi.oetiker.ch/lshort/lshort.pdf. – Zarko Aug 24 '17 at 00:32

1 Answers1

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

Mensch
  • 65,388
  • Wow ok i didn't think it would be that simple, thanks a lot!! – Jihane Sbaytti Aug 23 '17 at 23:54
  • What do you recommand then? – Jihane Sbaytti Aug 24 '17 at 00: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! – Jihane Sbaytti Aug 24 '17 at 00:29
  • sorry, you not catch the point. i'm not offend you, contrary, so no place for sarcasm here. – Zarko Aug 24 '17 at 00:35