0

I make a table by the following code in which a cell of the talbe is consctructed by a \makebox. Cells at the same line are seperated by \vrule. lines are seperated by \hrule.

In this example, I want horizontal rules made by \hrule to appear at the cell 11 and 13 other than 12 which means two horizontal rules made by \hrule are in the same line.

How can I do it?

\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{showframe}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}
\begin{document}
\fboxsep0pt
\fbox{\parbox{4in}{
    \makebox[\dimexpr 1in - 0.4pt][c]{\parbox{\dimexpr 1in - 2.4pt}{11}}%
    \vrule%
    \makebox[\dimexpr 2in - 0.4pt][c]{\parbox{\dimexpr 2in - 2.4pt}{12}}%
    \vrule%
    \makebox[\dimexpr 1in - 0.4pt][c]{\parbox{\dimexpr 1in - 2.4pt}{13}}%
    \hrule width 1in \hspace{2in} \hrule width 1in %of cause this is a wrong way.
    \makebox[\dimexpr 1in - 0.4pt][c]{\parbox{\dimexpr 1in - 2.4pt}{21}}
}}
\end{document}

Second version:

I tried to use \framebox like this, but why is the cell21 not at the second line? That is to say, why does it fail to feedline automatically?

\fbox{\parbox{4in}{\fboxsep3pt
    \framebox[\dimexpr 1in][c]{\parbox{\dimexpr 1in - 2.4pt}{11}}%
    \framebox[\dimexpr 2in][c]{\parbox{\dimexpr 2in - 2.4pt}{12}}%
    \framebox[\dimexpr 1in][c]{\parbox{\dimexpr 1in}{13}}%
    \framebox[\dimexpr 1in][c]{\parbox{\dimexpr 1in - 2.4pt}{21}}
  }}
6
  • same comment as last time. \hrule is a tex vertical mode primitive and so you can not have two on the same line. You could use the latex \rule or use \framebox instead of \makebox and let latex add the rules. Commented Feb 4, 2022 at 14:12
  • I tried framebox, What causes the problem of my second version?
    – lyl
    Commented Feb 4, 2022 at 15:22
  • like all latex boxes, \framebox is positioned by the same logic as a letter and you have 4 in a row like XXXX with no space or linebreak specified so naturally you get 4 on the same line. Commented Feb 4, 2022 at 15:29
  • If the content 11 changes to 11\\11a, the line fails to align horizontally. As the content of any cell can not be known in advance, any good idea for this problem?
    – lyl
    Commented Feb 4, 2022 at 16:26
  • you want all the parboxes to be \parbox[t] if you want the boxes to align on top baseline Commented Feb 4, 2022 at 16:43

1 Answer 1

2

You had specified no break points between the boxes. I believe the desired output is

enter image description here

\documentclass{article}

\begin{document}

\fbox{\parbox{4in}{\fboxsep3pt
    \framebox[\dimexpr 1in][c]{\parbox[t]{\dimexpr 1in - 2.4pt}{11}}%
    \framebox[\dimexpr 2in][c]{\parbox[t]{\dimexpr 2in - 2.4pt}{12}}%
    \framebox[\dimexpr 1in][c]{\parbox[t]{\dimexpr 1in}{13}}\\%
    \framebox[\dimexpr 1in][c]{\parbox[t]{\dimexpr 1in - 2.4pt}{21}}
  }}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .