如何在 aj,i 列上方(顶部)和 n 行前方(侧面)写入矩阵和文本?

如何在 aj,i 列上方(顶部)和 n 行前方(侧面)写入矩阵和文本?

这是我尝试过的,但未能产生预期的结果。请帮忙!“LaTex 环境”

\documentclass[12pt, a4paper, oneside]{article}
\hyphenation{Fortran hy-phen-ation} % Specify custom hyphenation points in words with dashes where you would like hyphenation to occur, or alternatively, don't put any dashes in a word to stop hyphenation altogether
%\usepackage[T1]{fontenc} % output font encoding for international characters
\usepackage[english]{babel} % English language/hyphenation
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage[utf8x]{inputenc}
%\usepackage{kpfonts}
%\DeclareUnicodeCharacter{211D} {\mathbb{R}}
%\DeclarationUnicodeCharacter{00A0} {}
%\DeclarationUnicodeCharacter{00A0} {~}
%\usepackage{fourier}
%\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{xfrac}
\usepackage{sectsty} % Allows customizing section commands
%\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps
\usepackage{multirow}
\usepackage{tikz}
\usepackage{booktabs}         %to use \toprule and \bottomrule without error message
\usepackage{pgfplots}         %to plot figure
\usepackage{threeparttable} 
\usepackage{booktabs}         %to use \toprule and \bottomrule without error message
\usepackage{pgfplots}   
\pgfplotsset{compat=1.5}
\usepackage{subfigure}        % to add subfigures
\usepackage{gensymb}
%\usepackage[none]{hyphenat}  %to prevent word breaking
\usepackage{siunitx}
\usepackage{caption}
\usepackage{booktabs} 
\newcommand*{\head}[1]{\textbf{#1}}%  to make heads of table in BOLD, it is used with booktabs package and \head
\usepackage{cleveref}
\usepackage{url} \makeatletter \g@addto@macro{\UrlBreaks}{\UrlOrds} \makeatother
\usepackage[justification=centering]{caption}
\PassOptionsToPackage{hyphens}{url}
%\usepackage{hyperref}
\usepackage{float}
%\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
%\usepackage[a4paper, portrait, margin=1in]{geometry}
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{pgfplots, pgfplotstable}
\usepackage{booktabs,csvsimple}
\usepackage{pdflscape}
%% packages
%\input{settings/packages}
%% page setting
%\input{settings/pages}
%% own comments
%\usepackage[margin=1in]{geometry}
\usepackage{amsmath, amsfonts, amsthm} % needed for command eqref or Math packages
\usepackage{amssymb} % needed for math fonts
%\usepackage{hyperref}
\usepackage[
    colorlinks=true
   ,breaklinks
   %, ngerman
    ] {hyperref} % needed for creating hyperlinks in the docuent, the option colorlink=true gets rid of the awful boxes, breaklinks breaks lonk links (list of figures), and the ngerman sets everthing for german s default hyperlink languages.
%\usepackage[hyphenbreaks]{breakurl} 
\usepackage{xcolor}
\definecolor {c1}{rgb}{0,0, 1} % blue
\definecolor {c2}{rgb}{0.3,0.3, 0.9} % light blue
\definecolor {c3}{rgb}{0.3,0.3, 0.9} % red blue
\hypersetup{
   linkcolor={c1}, % internal links
    citecolor={c2}, % citations 
    urlcolor={c3} % external links/urls
}

%\usepackage[round, authoryear]{natbib} % needed for abbrvant bibliography style
%\usepackage[nottoc]{tocbibind} % needed for displaying bibliography and other in the table of contents
\usepackage{graphicx} % needed for\includegraphics
%\imp{graphicx}
\usepackage{longtable} % needed for long tables over pages
\usepackage{bigstrut} % needed for the  command \bigstrut
\usepackage{enumerate} % needed for some options in enumerate
%\usepackage{todonotes} % needed for todos
\usepackage{makeidx}  % needed for creating an index
\usepackage{xcolor}
\usepackage{blindtext} % needed for creating dummy text passage
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage[nottoc, notlot, notlof]{tocbibind}
%% page settings%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[top=2cm, bottom=1.8cm, left=2.5cm, right=2.5cm]{geometry} % needed for page border stteings 
\parindent=0cm % for spece of first line of new text block
\sloppy % for writing with hypenless justification (tries to)
%\hyphenation {} % use hypenation of tolerance parameters, http://www.jr-x.de/publikationen/latex/tipps/zeilenumbruch_html
%\hyphenpenalty=10000
%\exhyphenpenalty=10000
%\usepackage{fancyhdr} % Custom headers and footers
%\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
%\usepackage[english]{babel} % English language/hyphenation
%\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
%\usepackage{sectsty} % Allows customizing section commands
%\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default 

%\usepackage[round, authoryear]{natbib} % needed for cite and abbrvnat bibliograph style
\usepackage[nottoc]{tocbibind} % needed for displayng bibliography and other in the able of contents
%\usepackage{figures}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pagestyle{fancy}
\fancyhf{}
%\cfoot{\thepage}
\fancyhead {}
\fancyfoot{}
\fancyhead[L]{\slshape \MakeUppercase {Multidimensional Poverty Index (MPI) in Ethiopia}}
%\fancyhead[R]{\slshape WELDESLASSIE HAILAI}
\fancyfoot[C]{\thepage}
%\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

%\setlength{\parindent}{4em} %This is going to change the width of that indent
%\setlength{\parskip}{1em} % This is going to change the amount of spacing in between your paragraphes if you want that
\renewcommand{\baselinestretch}{1.5}%This affects the in spacing of my paragraphes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\graphicspath{ {images/} }
\begin{titlepage}
\begin{center}
\vspace*{1cm}
\pagestyle{empty}
\pagestyle{plain}
......
$$
\begin{array}{cc}
\text{Income} & \text{Years of Education} & \text{Improved Sanitation} & \text {Access to improved Electricity &\\
\begin{bmatrix}
900 & 10 & Yes & Yes\\
300 & 15 & No  & Yes \\
400 & 9  & No  & No \\
800 & 12 & Yes & Yes\\
1000& 13 & No  &  No
\end{bmatrix} &
\begin{small}
Person_1\\
Person_2\\
Person_3\\
Person_4\\
Person_5\\
\end{small}
\end{array}
 $$
......
\end {doocument}

答案1

这是一个使用 和 的解决方案blkarraymakecell后者允许换行和由命令\thead和引入的常见单元格格式\makecell。我借此机会部分清理了不必要的软件包的前言并删除了软件包的双重加载。

\documentclass[12pt, a4paper, oneside]{article}
\usepackage[english]{babel} % English language/hyphenation
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage{xfrac}
\usepackage{multirow}
\usepackage{tikz}
\usepackage{pgfplots, pgfplotstable} %to plot figure
\usepackage{threeparttable}
\pgfplotsset{compat=1.5}
\usepackage{siunitx}
\usepackage{booktabs}
\newcommand*{\head}[1]{\textbf{#1}}% to make heads of table in BOLD, it is used with booktabs package and \head
\usepackage{url} \makeatletter \g@addto@macro{\UrlBreaks}{\UrlOrds} \makeatother
\usepackage[justification=centering]{caption}
\usepackage{float}
%\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
%\usepackage[a4paper, portrait, margin=1in]{geometry}
\usepackage{adjustbox}
\usepackage{tabularx, makecell}
\usepackage{booktabs,csvsimple}
\usepackage{pdflscape}
\usepackage{amsmath, amsfonts, amsthm} % needed for command eqref or Math packages
\usepackage{amssymb} % needed for math fonts
\usepackage[
    colorlinks=true
   ,breaklinks
   %, ngerman
    ] {hyperref} % needed for creating hyperlinks in the docuent, the option colorlink=true gets rid of the awful boxes, breaklinks breaks lonk links (list of figures), and the ngerman sets everthing for german s default hyperlink languages.
%\usepackage[hyphenbreaks]{breakurl}
\usepackage{cleveref}
\usepackage{xcolor}
\definecolor {c1}{rgb}{0,0, 1} % blue
\definecolor {c2}{rgb}{0.3,0.3, 0.9} % light blue
\definecolor {c3}{rgb}{0.3,0.3, 0.9} % red blue
\hypersetup{
   linkcolor={c1}, % internal links
    citecolor={c2}, % citations
    urlcolor={c3} % external links/urls
}
\usepackage{graphicx} % needed for\includegraphics
\usepackage{longtable} % needed for long tables over pages
\usepackage{bigstrut} % needed for the command \bigstrut
\usepackage{enumerate} % needed for some options in enumerate
\usepackage{blkarray}
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{fancyhdr}
%% page settings%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[top=2cm, bottom=1.8cm, left=2.5cm, right=2.5cm]{geometry} % needed for page border stteings
\parindent=0cm % for spece of first line of new text block
\sloppy % for writing with hypenless justification (tries to)
\pagestyle{fancy}
\fancyhf{}
\fancyhead {}
\fancyfoot{}
\fancyhead[L]{\slshape \MakeUppercase {Multidimensional Poverty Index (MPI) in Ethiopia}}
%\fancyhead[R]{\slshape WELDESLASSIE HAILAI}
\fancyfoot[C]{\thepage}
%\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\baselinestretch}{1.5}%This affects the in spacing of my paragraphes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\theadset{\renewcommand{\arraystretch}{0.6}}
\renewcommand\theadfont{\small}
\renewcommand\theadalign{bc}

\begin{document}

\begin{center}
\begin{blockarray}{rcccc}
 & \thead{Income} & \thead{Years of \\Education} & \thead{Improved\\ Sanitation} & \thead{Access to\\ improved \\ Electricity}\\
\begin{block}{>{\small}r[cccc]}
Person\textsubscript{1} & 900 & 10 & Yes & Yes\\
Person\textsubscript{2}& 300 & 15 & No & Yes \\
Person\textsubscript{3} & 400 & 9 & No & No \\
Person\textsubscript{4} & 800 & 12 & Yes & Yes\\
Person\textsubscript{5} & 1000& 13 & No & No\\
\end{block}
\end{blockarray}
\end{center}

\end{document} 

在此处输入图片描述

答案2

此解决方案使用 tikz 在表格上覆盖左括号和右括号。我删除了所有与问题无关的包。

\documentclass{standalone}
\usepackage{tikz}

\newlength{\tempwidth}
\newlength{\tempheight}

\begin{document}
\begin{tabular}{rcccc}
 & Income & Years of Education & Improved Sanitation & Access to improved Electricity \\
Person\textsubscript{1} & \tikz[remember picture]{\node[inner sep=0pt](First){900};} & 10 & Yes & Yes\\
Person\textsubscript{2}& 300 & 15 & No & Yes \\
Person\textsubscript{3} & 400 & 9 & No & No \\
Person\textsubscript{4} & 800 & 12 & Yes & Yes\\
Person\textsubscript{5} & 1000& 13 & No & \tikz[remember picture]{\node[inner sep=0pt](Last){No};}\\
\end{tabular}
\begin{tikzpicture}[remember picture,overlay]
  \pgfextractx{\tempwidth}{\pgfpointdiff{\pgfpointanchor{First}{west}}{\pgfpointanchor{Last}{east}}}%
  \pgfextracty{\tempheight}{\pgfpointdiff{\pgfpointanchor{Last}{south}}{\pgfpointanchor{First}{north}}}%
  \path (First.north west) -- (Last.south east) node[midway] {$\displaystyle \left[ \rule[-0.5\tempheight]{0pt}{\tempheight}% vertical strut
    \rule{\tempwidth}{0pt} \right]$};% horizontal strut
\end{tikzpicture}
\end{document} 

演示


就我个人而言,我不明白添加括号的原因。另一方面,如果数字右对齐并且仍然居中(或多或少),那就更好了,因此加上了 s \makebox

有多种方法可以计算的宽度\makebox,包括使用一列表格{@{}r@{}}

\documentclass{standalone}

\newlength{\firstcol}% width of first column (numbers only)
\newlength{\secondcol}% width of second column (numbers only)

\settowidth{\firstcol}{1000}% widest text
\settowidth{\secondcol}{15}

\begin{document}
\begin{tabular}{r|cccc}
 & Income & Years of Education & Improved Sanitation & Access to improved Electricity \\
\hline
Person\textsubscript{1} & \makebox[\firstcol][r]{900} & \makebox[\secondcol][r]{10} &Yes & Yes\\
Person\textsubscript{2}& \makebox[\firstcol][r]{300} & \makebox[\secondcol][r]{15} & No & Yes \\
Person\textsubscript{3} & \makebox[\firstcol][r]{400} & \makebox[\secondcol][r]{9} & No & No \\
Person\textsubscript{4} & \makebox[\firstcol][r]{800} & \makebox[\secondcol][r]{12} & Yes & Yes\\
Person\textsubscript{5} & \makebox[\firstcol][r]{1000} & \makebox[\secondcol][r]{13} & No & No \\
\end{tabular}
\end{document} 

演示

相关内容