1

I have a problem with boxes. I'd like to make it so that a box including 2 words align horizontally. So the first word is above the second word, in turn hopefully making the box smaller. This is what I have written so far:

\textbf{Elektriske komponenter}  & \textbf{Leverandør} & \textbf{Pris} & 
\textbf{Enhed} & \textbf{Antal} & \textbf{Sum i kr}

In which i'd like the ''Elektriske komponenter'' to be aligned, with ''Elektriske'' above ''komponenter'' in a box. I have created a table so far, but can't seem to find a solution, as to how to make words inside the box align like this.

  • 3
    Could you please (1) add a compilable example code not a description of your code and (2) a sketch of what your "boxes" would look like – user156344 May 20 at 14:12
  • 1
    Welcome to TeX.SE. Please indicate whether you use a tabular environment and, if so, which column types you employ for 6 columns. – Mico May 20 at 14:29
1

Something like this?

enter image description here

\documentclass{article}
\usepackage[danish]{babel} % is this correct?
\usepackage[T1]{fontenc}
\usepackage{array,booktabs}
\newlength\mylen % define a length "variable"

\begin{document}
\begin{table}
% Compute required width of 1st column:
\settowidth{\mylen}{\textbf{komponenter}} 
\centering
\begin{tabular}{@{} p{\mylen} *{5}{c} @{}}
\toprule
\textbf{Elektriske komponenter}  & \textbf{Leverandør} &
\textbf{Pris} & \textbf{Enhed} & 
\textbf{Antal} & \textbf{Sum i kr} \\
\midrule
\end{tabular}
\end{table}
\end{document}
  • Why measuring? \textbf{\begin{tabular}[t]{@{}l@{}}Elektriske \\ komponenter\end{tabular}} will do the same without needing to measure. – egreg May 20 at 15:09
  • @egreg — Thanks. Let’s see if the OP sees fit to provide some much-needed additional information about the setup of the (outer) tabular environment and about what kind of text will show up at n the first column. – Mico May 20 at 15:41

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.