3

I have the following latex text written in overleaf document:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{test}
\author{spanos.nikolaos }
\date{July 2020}

\begin{document}

\maketitle

\section{Introduction}

\textbf{Assign each array of weights to the relative actor name}

\begin{equation}
\textrm{Daniel Craig} = 
\begin{bmatrix} -0.42056742 & -0.3540595 & -0.25417486 & -0.50596726 & -0.29918054\\ -0.23971583 & -0.39325562 & -0.35581827 & -0.3175518 & -0.2992685\\ -0.26149312 & -0.3268542 & -0.34264958 & -0.50005287 & -0.41450888\\ \ldots (m=60)
\end{bmatrix} = shape(5x60)
\end{equation}

\begin{equation}
\textrm{Tobey Maguire} = \begin{bmatrix} -0.30834767 & -0.26681098 & -0.2173222  & -0.11151562 & -0.27951762\\ -0.1721798 & -0.25406063 & -0.38693774 & -0.19798501 & -0.257399\\ -0.05970115 & -0.2399106 & -0.21202469 & -0.28024384 & -0.2577843\\ \ldots (m=60) 
\end{bmatrix}= shape(5x60)
\end{equation}

\end{document}

However, both equations go out of the right margin, like is shown in the image below, enter image description here

I know that there are many similar questions on this matter, however, I am new in Latex and I don't understand how to apply most of the solutions I found on my much simple case. Thank you in advance for any suggestion and I apologize if this is a duplicate.

Update 1 Based on an answer on the comments section, by using this command \textrm{Tobey Maguire} I managed to overcome the extra space and wrong names problem, so I got this,

enter image description here

Update 2 - relative to the reproducible code added

I opened a new Overleaf blank page and I added the code above (with packages) And I got the following shot,

enter image description here

Since the 2 screenshots added earlier are from a pre-defined template I don't know where the page margins are. Also, I don't know the default Latex margins of Overleaf. Because you can see in the screenshots that the letters are much smaller. How can I modify the page margins in Latex?

6
  • Hi and welcome. Please give a fully compilable code.
    – AndréC
    Jul 19 '20 at 9:44
  • @AndréC Hey, what do you mean compilable? Like also libraries (packages) I used? Sorry It's my 1st time here. :)
    – NikSp
    Jul 19 '20 at 9:49
  • 1
    @NikSp: A minimal working example (MWE) also contains the documentclass as well as the relevant packages.
    – leandriis
    Jul 19 '20 at 9:53
  • 1
    you should not have \ \\ in an equation (it doesn't do anything useful) and words should not be in math italic so \textrm{David Lewis} but we can not tell you how to make it fit if you do not show an example showing how wide your page is. Jul 19 '20 at 9:53
  • 1
    @NikSp LaTeX is a language that, like C, Pascal and others, is compiled on the contrary of javascript and PHP which are interpreted. Thus, a document is fully compilable when you only need to copy and paste the code to produce the PDF output. This saves users from having to search painfully for the packages your document needs to produce the PDF. Then, as leandriis says, having an MWE is the basis of the questions, see on this subject How to make a minimum example.
    – AndréC
    Jul 19 '20 at 10:56
5

Do you really need to give the values to so many decimal places? If so you need to shrink the font something like this, but if possible I'd print at normal size but use 3 decimal places or whatever is suitable.

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}


\paragraph{Assign each array of weights to the relative actor name}
\small
\begin{align}
\begin{split}
\rlap{\text{David Lewis}}\\
 &= \begin{bmatrix} -0.42056742 & -0.3540595 & -0.25417486 & -0.50596726 & -0.29918054\\ -0.23971583 & -0.39325562 & -0.35581827 & -0.3175518 & -0.2992685\\ -0.26149312 & -0.3268542 & -0.34264958 & -0.50005287 & -0.41450888\\ \ldots (m=60)
\end{bmatrix}\\
& = \operatorname{shape}(5\times60)
\end{split}
\\
\begin{split}
\rlap{\text{James Gandolfini}}\\
& = \begin{bmatrix} -0.30834767 & -0.26681098 & -0.2173222  & -0.11151562 & -0.27951762\\ -0.1721798 & -0.25406063 & -0.38693774 & -0.19798501 & -0.257399\\ -0.05970115 & -0.2399106 & -0.21202469 & -0.28024384 & -0.2577843\\ \ldots (m=60) 
\end{bmatrix}\\
&= \operatorname{shape}(5\times60)
\end{split}
\end{align}
%no!!\ \\

\end{document}
3
  • Thanks for your answer David. It seems to fit perfectly to my case.
    – NikSp
    Jul 19 '20 at 10:09
  • From your answer, I can understand how new I am in Latex, that even there is a shape operator and I was using a word for it. Thanks again David, very well structured answer and actually helps me for similar cases
    – NikSp
    Jul 19 '20 at 10:13
  • 1
    @NikSp there isn't a shape operator predefined but \operatorname{foobar} makes a roman foobar operator with the same spacing as \log or \sin predefined operators Jul 19 '20 at 10:16
3

You need to reduce the font size, if you want to fit such big objects.

I propose a solution with siunitx and a tabular built in text mode via lrbox.

You can choose the font size as an optional argument to weightmatrix.

\documentclass{article}
\usepackage{amsmath,siunitx}

\DeclareMathOperator{\shape}{shape}
\newsavebox{\weightmatrixbox}
\newenvironment{weightmatrix}[1][\normalsize]
 {%
  \left[
  \begin{lrbox}{\weightmatrixbox}#1% a size changing command
  \setlength{\tabcolsep}{0.5\tabcolsep}%
  \begin{tabular}{@{}*{5}{S[table-format=-1.8]}@{}}%
 }
 {\end{tabular}\end{lrbox}\usebox{\weightmatrixbox}\right]}

\title{test}
\author{spanos.nikolaos}
\date{July 2020}

\begin{document}

\maketitle

\section{Introduction}

\subsection*{Assign each array of weights to the relative actor name}

\begin{align}
&\text{Daniel Craig} \notag\\
& = 
\begin{weightmatrix}[\footnotesize]
  -0.42056742 & -0.3540595  & -0.25417486 & -0.50596726 & -0.29918054 \\
  -0.23971583 & -0.39325562 & -0.35581827 & -0.3175518  & -0.2992685  \\
  -0.26149312 & -0.3268542  & -0.34264958 & -0.50005287 & -0.41450888 \\
  \ldots (m=60)
\end{weightmatrix} \\
& = \shape(5 \times 60) \notag \\[2ex]
&\text{Tobey Maguire} \notag\\
& =
\begin{weightmatrix}[\footnotesize]
  -0.30834767 & -0.26681098 & -0.2173222  & -0.11151562 & -0.27951762 \\
  -0.1721798  & -0.25406063 & -0.38693774 & -0.19798501 & -0.257399   \\
  -0.05970115 & -0.2399106  & -0.21202469 & -0.28024384 & -0.2577843  \\
  \ldots (m=60) 
\end{weightmatrix} \\
&= \shape(5 \times 60) \notag
\end{align}

\end{document}

enter image description here

1
  • Way too much advanced for my level of Latex knowledge. An also exceptional answer. Thanks for your reply egreg!
    – NikSp
    Jul 19 '20 at 11:03
1

Another possibility is to position the page in landscape mode.

\documentclass[landscape]{article}

screenshot

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[margin=10mm]{geometry}
\title{test}
\author{spanos.nikolaos }
\date{July 2020}

\begin{document}

\maketitle

\section{Introduction}

\textbf{Assign each array of weights to the relative actor name}

\begin{equation}
\textrm{Daniel Craig} = 
\begin{bmatrix} -0.42056742 & -0.3540595 & -0.25417486 & -0.50596726 & -0.29918054\\ -0.23971583 & -0.39325562 & -0.35581827 & -0.3175518 & -0.2992685\\ -0.26149312 & -0.3268542 & -0.34264958 & -0.50005287 & -0.41450888\\ \ldots (m=60)
\end{bmatrix} = shape(5x60)
\end{equation}

\begin{equation}
\textrm{Tobey Maguire} = \begin{bmatrix} -0.30834767 & -0.26681098 & -0.2173222  & -0.11151562 & -0.27951762\\ -0.1721798 & -0.25406063 & -0.38693774 & -0.19798501 & -0.257399\\ -0.05970115 & -0.2399106 & -0.21202469 & -0.28024384 & -0.2577843\\ \ldots (m=60) 
\end{bmatrix}= shape(5x60)
\end{equation}

\end{document}

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.