TransWikia.com

weird text place on the top of the column with makecell in latex table

TeX - LaTeX Asked by Apinorr on November 26, 2021

I want that the text is placed in the top of the column in my table. I have the following code:

documentclass[a4paper,12pt]{scrreprt}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{makecell} % sauter une ligne dans un tableau


begin{document}

begin{table}[H]
   centering
   begin{tabular}{m{2cm} m{13cm}} 
        Authors:& my name \
        Date:& today \
        Lecture:& Essentials of advanced astrophysics \
        Lecturer:&  my prof \ hline hline
        makecell[l]{Declaration: \ \ \ \ \ } & I hereby declare that this thesis is my own work and that I have not used any sources and aids other than those stated in the thesis. I [AGREE/DO NOT AGREE] with making this document available to other students of the course on a password protected website. [PLACE], [DATE][NAME][SIGNATURE] 
    end{tabular}
end{table}

end{document}

but it shows me this:

enter image description here

As you can see, Declaration and I hereby are not on the same line… Does anyone knows why and how I can fix it ?

One Answer

m type columns will result in vertically centered text. Since you seem to want to top align the text in your table, use p type columns and drop the makecell command.

In the following MWE, I have also included a second version of your table, using the tabularx package. With this package, you can automatically adjust the width of a table to the textwidth (or another width of your choice).

In the following screenshot, the red lines indicate the textwidth:

enter image description here

documentclass[a4paper,12pt]{scrreprt}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{makecell} % sauter une ligne dans un tableau

usepackage{tabularx}

begin{document}

%begin{table}[H]
%   centering
noindent
   begin{tabular}{p{2cm} p{13cm}} 
        Authors:& my name \
        Date:& today \
        Lecture:& Essentials of advanced astrophysics \
        Lecturer:&  my prof \ hline hline
        Declaration: & I hereby declare that this thesis is my own work and that I have not used any sources and aids other than those stated in the thesis. I [AGREE/DO NOT AGREE] with making this document available to other students of the course on a password protected website. [PLACE], [DATE][NAME][SIGNATURE] 
    end{tabular}
%end{table}

noindent
   begin{tabularx}{textwidth}{@{} l X @{}} 
        Authors:& my name \
        Date:& today \
        Lecture:& Essentials of advanced astrophysics \
        Lecturer:&  my prof \ hline hline
        Declaration: & I hereby declare that this thesis is my own work and that I have not used any sources and aids other than those stated in the thesis. I [AGREE/DO NOT AGREE] with making this document available to other students of the course on a password protected website. [PLACE], [DATE][NAME][SIGNATURE] 
    end{tabularx}

end{document}

Answered by leandriis on November 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP