3

I'm still new to LaTeX, and I have a litle problem, I have a table with 3 columns and one row, the first and last column are equal, and the middle take all the space. But I want to center content of it. When I use \centering I got the result in the image bellow. Is there any solution?

 \begin{table} \begin{tabularx}{\linewidth}{|m{3cm}|X|m{3cm}|} \hline \begin{minipage}{\textwidth} \includegraphics[width=3cm, height=2.5cm]{ump.png} \end{minipage} & \begin{minipage}{\textwidth} \centering Université Mohamed Premier \\ École Nationale de Commerce et de Gestion \\ Oujda. \\ \end{minipage} & \begin{minipage}{\textwidth} \includegraphics[width=3cm, height=2.5cm]{ump.png} \end{minipage} \\ \hline \end{tabularx} \end{table} 

Code Results

Thank you very much.

2
  • 1
    A quick fix: use \linewidth instead of \textwidth for the middle minipage Commented May 5, 2017 at 10:44
  • 1
    you don't need any of the minipages, just remove them, nor (I suspect) do you want the table environment Commented May 5, 2017 at 10:46

4 Answers 4

1
 \documentclass[a4paper]{article} \usepackage{tabularx} \usepackage{graphicx} \begin{document} \begin{table} \begin{tabularx}{\linewidth}{|m{3cm}|>{\centering\arraybackslash}X|m{3cm}|} \hline \includegraphics[scale=3.1]{2.png} & \vspace*{-9mm} Université Mohamed Premier\newline Ecole Nationale de Commerce et de Gestion\newline Oujda. & \vspace*{5mm} \includegraphics[scale=3.1]{2.png} \\ \hline \end{tabularx} \end{table} \end{document} 

enter image description here

1
  • You're missing \usepackage[T1]{fontenc}. Commented May 5, 2017 at 11:19
3

enter image description here

You do not need the inner minipage or the outer table environment. It is probably simpler not to use tabularx either.

\documentclass{article} \usepackage{tabularx,graphicx} \begin{document} \noindent \renewcommand\tabularxcolumn[1]{m{#1}} \begin{tabularx}{\linewidth}{|m{3cm}|X|m{3cm}|} \hline \includegraphics[width=\linewidth]{example-image-a} & \centering Université Mohamed Premier \\ École Nationale de Commerce et de Gestion \\ Oujda. & \includegraphics[width=\linewidth]{example-image-b} \\ \hline \end{tabularx} \bigskip But simpler you don't need a table at all \bigskip \noindent \mbox{\includegraphics[width=2.5cm]{example-image-a}% \hfill \begin{tabular}[b]{c} Université Mohamed Premier \\ École Nationale de Commerce et de Gestion \\ Oujda. \end{tabular}% \hfill \includegraphics[width=2.5cm]{example-image-b}} \end{document} 
6
  • Dear sir I am new to latex please let me know the use of \noindent, when i remove the \noindent the output is still the same @David Carlisle Commented May 5, 2017 at 11:23
  • oops I'm missing \usepackage[utf8]{inputenc} so the accented characters work. Commented May 5, 2017 at 11:23
  • @BikiTeron without \noindent the start of a paragraph (which is the first image here) is indented by \parindent (15pt in report class) Commented May 5, 2017 at 11:24
  • Sir can you please show with the figures so that i can make differentiate @David Carlisle, thanking you in advance. Commented May 5, 2017 at 11:28
  • @BikiTeron really you shouldn't ask unconnected questions as comments under an answer, just try it yourself: remove the first \noindent in the code I posted and tex's log will tell you Overfull \hbox (15.0pt too wide) in paragraph at lines 29--30 as the line will have been shifted 15pt to the right Commented May 5, 2017 at 11:41
3

Use a simple tabular for each cell. This way, you get the logos vertically centered automatically as well as the text in the middle. You will also need a >{\centering} before the middle column to make it horizontally centered.

\documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage{graphicx,tabularx} \usepackage[margin=1in]{geometry} \begin{document} \newcommand{\cell}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}} \begin{table} \begin{tabularx}{\linewidth}{|c|>{\centering}X|c|} \hline \cell{\includegraphics[scale=3]{logo.png}} & \cell{Université Mohamed Premier \\ École Nationale de Commerce et de Gestion\\ Oujda.} & \cell{\includegraphics[scale=3]{logo.png}} \\ \hline \end{tabularx} \end{table} \end{document} 

[1]: https://i.sstatic.net/pRt

0
3

As I don't think this will have to float (looks like a header), I removed the table environment. Centring is obtained by redefining the X columntype and using the valign key from adjustbox:

\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage{graphicx, adjustbox} \usepackage{tabularx, cellspace} \renewcommand{\tabularxcolumn}[1]{m{#1}} \begin{document}% \begin{tabularx}{\linewidth}{|Sc|X|Sc|} \noalign{\setlength{\cellspacetoplimit}{0pt}} \hline \adjincludegraphics[width=3cm, valign=c]{ump.png} & \centering Université Mohammed Premier \\ École Nationale de Commerce\\ et de Gestion \\ Oujda. & \adjincludegraphics[width=3cm, valign=c]{ump.png}\\ \hline \end{tabularx} \end{document} 

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.