0

This is the code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m) {
    a_1&b_{1,2}&0&\cdots&0&b_{1,s_1+1}&0&0&\cdots&0&b_{2,s_2+1} \\
    b_{1,2}&a_2&b_{1,3} \\
    &\ddots&\ddots&\ddots \\
    &&b_{1,s_1-1}&a_{s_1-1}&b_{1,5} \\
    &&&b_{1,s_1}&a_{s_1}\\
    b_{1,s_1+1}&&&&0&a_{s_1+1}&b_{2,s_1+2} \\
    &&&&&b_{2,s_2+2}&a_{s_1+2}&b_{2,s_1+3}\\
    &&&&&&\ddots&\ddots&\ddots \\
    &&&&&&&b_{1,s_1-1}&a_{s_1-1}&b_{1,s_3} \\
    &&&&&&&&b_{1,5}&a_{s_2-1}   \\
    b_{2,s_2+1}&&&&&&&&&0&a_{s_3-1}&b_{1,s_3+1}\\       
    &&&&&&&&&&&&2&a_{s_3-1}&b_{1,s_3+1}\\               
    &&&&&&&&&&\ddots&\ddots&\ddots\\
    &&&&&&&&&&&1&2&3\\
};  
\node[above=10pt of m-1-1] (top-1){};
\node[above=10pt of m-1-3] (top-3){};
\node[above=10pt of m-1-4] (top-4){};
\node[above=10pt of m-1-5] (top-5){};   
\node[above=10pt of m-1-6] (top-6){};



\node[rectangle,above delimiter=\{] (del-top-3) at ($0.5*(top-3.south) +0.5*(top-5.south)$) {\tikz{\path (top-3.south west) rectangle (top-5.north east);}};
\node[above=5pt] at (del-top-3.north) {$N_1-1$};
\end{tikzpicture}

\end{center}
\end{document}

And this is the result

enter image description here

The matrix is floating to the right and the rest of it is invisible. How can I center it?

1 Answer 1

1

Your matrix is already centred, unfortunately it is wider than the available text width. Best would be to restructure it to fit within the available text width. If this is not possible, you could adjust the margins to accommodate the matrix:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}

\usepackage{changepage} 

\begin{document}
\begin{adjustwidth}{-7.6em}{-7.6em}
\begin{tikzpicture}
\matrix [matrix of math nodes,left delimiter=(,right delimiter=)] (m) {
    a_1&b_{1,2}&0&\cdots&0&b_{1,s_1+1}&0&0&\cdots&0&b_{2,s_2+1} \\
    b_{1,2}&a_2&b_{1,3} \\
    &\ddots&\ddots&\ddots \\
    &&b_{1,s_1-1}&a_{s_1-1}&b_{1,5} \\
    &&&b_{1,s_1}&a_{s_1}\\
    b_{1,s_1+1}&&&&0&a_{s_1+1}&b_{2,s_1+2} \\
    &&&&&b_{2,s_2+2}&a_{s_1+2}&b_{2,s_1+3}\\
    &&&&&&\ddots&\ddots&\ddots \\
    &&&&&&&b_{1,s_1-1}&a_{s_1-1}&b_{1,s_3} \\
    &&&&&&&&b_{1,5}&a_{s_2-1}   \\
    b_{2,s_2+1}&&&&&&&&&0&a_{s_3-1}&b_{1,s_3+1}\\       
    &&&&&&&&&&&&2&a_{s_3-1}&b_{1,s_3+1}\\               
    &&&&&&&&&&\ddots&\ddots&\ddots\\
    &&&&&&&&&&&1&2&3\\
};  
\node[above=10pt of m-1-1] (top-1){};
\node[above=10pt of m-1-3] (top-3){};
\node[above=10pt of m-1-4] (top-4){};
\node[above=10pt of m-1-5] (top-5){};   
\node[above=10pt of m-1-6] (top-6){};
\node[rectangle,above delimiter=\{] (del-top-3) at ($0.5*(top-3.south) +0.5*(top-5.south)$) {\tikz{\path (top-3.south west) rectangle (top-5.north east);}};
\node[above=5pt] at (del-top-3.north) {$N_1-1$};
\end{tikzpicture}
\end{adjustwidth}
\end{document}

You must log in to answer this question.

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