[Tex/LaTex] How to make a box with fixed size

boxes

\parbox[pos][height][contentpos]{width}{text} gives me a box where height is actually "minimal height", while width= exact width. I would like height to also be "exact height". How can I do this? Text that is larger then the content should

  1. disappear "within the box" and not appear outside the boxes borders or
  2. be adjusted in size so that it fits into the box.

Though I think 2 is asking to much.

Here is how far I got:

\RequirePackage[l2tabu, orthodox]{nag}      % Warning when old or wrong commands are used
\RequirePackage{fix-cm}             % permits Computer Modern fonts at arbitrary sizes
\documentclass[a4paper,10pt,oneside]{article}

\usepackage{geometry}
\usepackage{blindtext}
\usepackage{adjustbox}

\usepackage[many]{tcolorbox}
\usepackage{lmodern}% or any other vector / postscript font
\usepackage{lipsum}

\geometry{
    a4paper,
    centering,
    hmargin=0.5mm,
    vmargin=1mm,
    ignoreall,
    showframe
}

\setlength{\parindent}{0cm}
\setlength{\fboxsep}{0pt}

\begin{document}
\selectlanguage{ngerman}
\renewcommand{\familydefault}{\sfdefault}
\pagestyle{empty}

\newcommand{\myboxI}{%
\fbox{\adjustbox{totalheight=21.2mm, width=52.5mm, keepaspectratio, rotate=0, minipage=[r][21.2mm][t]{52.5mm}}{%
    wefewf wwkeföjwlkej fkewjf ölkewjflkewjf \\ ölkewjf lwkejf lkwjlkwejf lkwejf \\ asdf wef we \\ werwer we \\ werwerewfewfewfewfewfwef wef ewf ewf wef we f \\ wefewf wefwe%
}}%
}

\newcommand{\myboxII}{%
\begin{tcolorbox}[%
  fit,width=52.5mm,height=21.2mm,blank,
  borderline={0.4pt}{0pt}{red!20!white},
  %watermark text={6cm $\times$ 6cm},nobeforeafter
  ]
  wefewf wwkeföjwlkej fkewjf ölkewjflkewjf \\ ölkewjf lwkejf lkwjlkwejf lkwejf \\ asdf wef we \\ werwer we \\ werwerewfewfewfewfewfwef wef ewf ewf wef we f \\ wefewf wefwe
\end{tcolorbox}%
}

\myboxI\hspace{-1cm}\hfill\myboxI\hspace{-1cm}\hfill\myboxI\hspace{-1cm}\hfill\myboxI

\bigskip

\myboxII\hspace{-1cm}\hfill\myboxII\hspace{-1cm}\hfill\myboxII\hspace{-1cm}\hfill\myboxII

\end{document}

enter image description here

The first attempt does not really scale the content, as I had hoped. Also I had expected that the boxes are just next to each other, not overlap.

The second does not allow the boxes to be next to each other.

Best Answer

Problem 2 is treated elsewhere on the site, I'll deal only with problem 1, which can be solved with \vsplit.

\documentclass{article}
\usepackage{xparse}
\usepackage{microtype}
\usepackage[margin=1cm]{geometry}

\usepackage{lipsum}

\ExplSyntaxOn
\box_new:N \l_hideparbox_box

\NewDocumentCommand{\hideparbox}{O{c}mm+m}
 {% #1=alignment, #2=height, #3=width, #4=text
  \group_begin:
  \vbox_set:Nn \l_hideparbox_box
   {
    \use:c { @parboxrestore }
    \hsize=#3\scan_stop:
    \strut#4\par
   }
  \vbadness=\c_ten_thousand % no spurious underfull messages
  \vbox_set_split_to_ht:NNn \l_hideparbox_box \l_hideparbox_box { #2 }
  \parbox[#1][#2]{#3}
   {
    \vbox_unpack:N \l_hideparbox_box
   }
  \group_end:
 }
\ExplSyntaxOff

\begin{document}

\fboxsep=0pt % just for the example

\fbox{\hideparbox{3cm}{7cm}{\lipsum*[1]}}
\fbox{\hideparbox{6cm}{7cm}{\lipsum*[1]}}

\fbox{\hideparbox[t]{3cm}{7cm}{\lipsum*[1]}}
\fbox{\hideparbox[t]{6cm}{7cm}{\lipsum*[1]}}

\fbox{\hideparbox[b]{3cm}{7cm}{\lipsum*[1]}}
\fbox{\hideparbox[b]{6cm}{7cm}{\lipsum*[1]}}

\end{document}

I load microtype just for convenience, in order to minimize overfull boxes. Also \fbox is used just for showing the boundaries of the boxes.

The idea is to typeset the box and then prune off everything beyond the stated limit.

enter image description here