6

Consider the following MWE:

\documentclass[letterpaper,11pt]{article}
\usepackage{geometry}%[showframe]
\usepackage{array}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{fontspec}
 
\setmainfont{Arial}%{Times New Roman}
\newcommand{\logo}{\includegraphics[scale=0.125]{images/logo.pdf}}

\newlength{\logodim}
\newlength{\headerdim}
\settowidth{\logodim}{\logo}
\setlength{\headerdim}{\dimexpr\linewidth-\logodim-\tabcolsep\relax}

\setlength{\parindent}{0pt}
\begin{document}
{\setlength{\tabcolsep}{0.5em}
    \begin{tabular}{@{}m{\logodim}m{\headerdim}@{}}%
        \logo & %
        \parbox{\headerdim}{%
            {\bfseries University Name}\\%
            Department Name%
        }   %
    \end{tabular}}
    \\[1ex]
\setlength{\tabcolsep}{0em} 
\begin{tabular}{p{0.75\linewidth}p{0.25\linewidth}<{\raggedleft\arraybackslash}}
    \toprule
    \textbf{CALCULUS} & \textbf{MATH2301}\\[0.5ex]
    M1 T1: Precalculus & Semster 1\\[0.5ex]
    Maximum Marks: 100 & October, 2020\\[0.5ex]
    \bottomrule
\end{tabular}
\end{document}

What are the new L3 commands for \newlength, \settowidth, \setlength and \dimexpr? Can you also point me to the documentation where these can be found?

  • Wouldn't it be easier to just ue tabularx for the first tabular? With this approach, there is no need to measure the width of the image, nor to calculate the width of the second column. – leandriis Oct 25 at 19:32
  • @leandriis Indeed. I guess am looking at it from a tabular perspective. :) I personally haven't used tabularx but you can provide a MWE with it. – azetina Oct 25 at 19:37
8

Concerning the initial question of the OP.

What are the new L3 commands for \newlength, \settowidth, \setlength and \dimexpr? Can you also point me to the documentation where these can be found?

Here is the corresponding functions in expl3 (however, these functions are not meant to be used by the final user but rather by the developper of packages and classes).

  • Instead of \newlength, you use \dim_new:N.

  • Instead of \setlength, you use \dim_set:Nn (or \dim_gset:Nn for a global assignment). You don't need \dimexpr because you can put a computation in the second argument of \dim_set:Nn: \dim_set:Nn \l_tmpa_dim { 1 cm + 2 mm }.

  • Instead of \settowidth, you use something such as : \hbox_set:Nn \l_tmpa_box { My text } \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }

These functions are described in the document interface3.pdf. Use texdoc interface3.pdf in a terminal.

| improve this answer | |
6

I'm not sure why you're doing all those measurements.

\documentclass[letterpaper,11pt]{article}
\usepackage{geometry}%[showframe]
\usepackage{array}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{fontspec}
 
\setmainfont{Arial}%{Times New Roman}
\newcommand{\logo}{\includegraphics[scale=0.125]{example-image}}

\begin{document}

\noindent
\begin{tabular}{@{}c@{}} \logo \end{tabular}\enspace
\begin{tabular}{@{}l@{}}
  \bfseries University Name \\
            Department Name
\end{tabular}

\noindent
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lr@{}}
\toprule
\textbf{CALCULUS} & \textbf{MATH2301}\\[0.5ex]
M1 T1: Precalculus & Semester 1\\[0.5ex]
Maximum Marks: 100 & October, 2020\\
\bottomrule
\end{tabular*}

\end{document}

enter image description here

Picture with showframe added:

enter image description here

| improve this answer | |
  • Interesting use of tabular*. I was trying to find a way to ensure the table fits in the \textwidth – azetina Oct 25 at 23:08
  • @azetina That's what tabular* is for: it ensures (provided we use it correctly) that the table fits the given width. – egreg Oct 25 at 23:14
  • Amazing. Am currently revising my template that I use and working on a base file to create .sty file; thus, the need for the measurements. I will need to create some commands and general settings. Any recommendations? Do you have a well established template maybe from a university? I honestly will need to create keyval statemetns for the parameters you see above. For example, University Name, Department Name, etc. Any recommendations? :) – azetina Oct 25 at 23:27
3

Here are two alternatives. The first one uses tabularx in combination with the valign option from the adjustbox package, the second example only uses a tabular to place the two lines of text below each other.

enter image description here

\documentclass[letterpaper,11pt]{article}
\usepackage{geometry}%[showframe]
\usepackage{array}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage[export]{adjustbox}
\usepackage{tabularx}
\usepackage{fontspec}
 
\setmainfont{Arial}%{Times New Roman}
\newcommand{\logo}{\includegraphics[scale=0.25,valign=c]{example-image}}


\setlength{\parindent}{0pt}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
{\setlength{\tabcolsep}{0.5em}
    \begin{tabularx}{\textwidth}{@{}lX@{}}%
        \logo & %
            {\bfseries University Name}\newline
            Department Name%
    \end{tabularx}}
    \\[1ex]
\setlength{\tabcolsep}{0em} 
\begin{tabular}{p{0.75\linewidth}p{0.25\linewidth}<{\raggedleft\arraybackslash}}
    \toprule
    \textbf{CALCULUS} & \textbf{MATH2301}\\[0.5ex]
    M1 T1: Precalculus & Semster 1\\[0.5ex]
    Maximum Marks: 100 & October, 2020\\[0.5ex]
    \bottomrule
\end{tabular}

\bigskip


    \logo \hspace{1em} \begin{tabular}{l} {\bfseries University Name}\\ Department Name \end{tabular}
    \\[1ex]
\setlength{\tabcolsep}{0em} 
\begin{tabular}{p{0.75\linewidth}p{0.25\linewidth}<{\raggedleft\arraybackslash}}
    \toprule
    \textbf{CALCULUS} & \textbf{MATH2301}\\[0.5ex]
    M1 T1: Precalculus & Semster 1\\[0.5ex]
    Maximum Marks: 100 & October, 2020\\[0.5ex]
    \bottomrule
\end{tabular}
\end{document}
| improve this answer | |
  • X calculates the difference of the size of the logo with the linewidth. Right? This will sure help. Thanks. Any suggestions for the L3 commands? – azetina Oct 25 at 19:46
  • @azetina: Yes, the X type column's width is calculated to make the overall width of the tabularx equal to the specified width (\textwidth in case of this specific example) Regarding L3 commands: unfortunately not. – leandriis Oct 25 at 19:49

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.