我写了以下代码:
\documentclass[a4paper,twoside,12pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{sansmathfonts}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{amsthm,amsfonts,amssymb,fge,mathtools}
\usepackage{parskip}
\usepackage{tabstackengine}
\setstackEOL{\cr}
\setstacktabbedgap{2pt}
\setstackgap{L}{8pt}
\pagestyle{empty}
\author{}
\date{}
\title{}
\begin{document}
$\boxed{\Matrixstack{\bullet & \bullet & \bullet & \bullet \cr \bullet & \bullet & \bullet & \bullet \cr \bullet & \bullet & \bullet & \bullet \cr \bullet & \bullet & \bullet & \bullet \cr \bullet & \bullet & \bullet & \bullet}}$
\end{document}
输出结果如下:
但我不想在方框和项目符号之间留出额外的垂直空间。我该如何删除它?
答案1
它比你想象的要容易。
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\scatola}{mm}
{% #1 = number of rows, #2 = number of columns
\group_begin:
\setlength{\fboxsep}{0pt}
\fbox{$\federico_scatola:nn { #1 } { #2 }$}
\group_end:
}
\cs_new_protected:Nn \federico_scatola:nn
{
\begin{array}{*{#2}{c}}
\prg_replicate:nn { #1 } { \bullet \prg_replicate:nn { #2 - 1 } { & \bullet } \\ }
\end{array}
}
\ExplSyntaxOff
\begin{document}
$\scatola{1}{5}\times\scatola{1}{4} = \scatola{5}{4}$
\end{document}
我在这里添加了您想要在问题原始版本中重现的图片。
答案2
例如使用 OpTeX:
\def\bbullets #1x#2 {%
\frame{\vbox{\fornum 1..#2\do{\hbox{\fornum 1..#1\do{\mybullet}}}}}
}
\def\mybullet{\strut\kern.3em$\bullet$\kern.3em}
% test:
\bbullets 3x4
\bye
答案3
尝试一下这种简单的格式:
\documentclass{book}
\usepackage{mathtools}
\begin{document}
\newcommand{\fourbullets}{\bullet &\bullet &\bullet &\bullet}%
\newcommand{\fivebullets}{\bullet &\bullet &\bullet &\bullet &\bullet}%
$
\fbox{$\begin{array}{ccccc}
\fivebullets
\end{array}
$}
\times
\fbox{$
\begin{array}{ccccc}
\fourbullets
\end{array}$
}=
\fbox{$
\begin{array}{ccccc}
\fivebullets\\
\fivebullets\\
\fivebullets\\
\fivebullets\\
\fivebullets
\end{array}$
}
$
\end{document}
但wipet
已经给出了最佳的自动建议。