# How to draw the Queen's moves on a chessboard?

I saw on the Internet a lecture with the title 8 QUEENS PROBLEM USING BACK TRACKING. There is a drawing of the Board following. How to make this using the Latex? (I tried using the package Chessboard, but the result is very different)

\documentclass{article}
\usepackage{chessboard}
\storechessboardstyle{8x8}{maxfield=d8}
\begin{document}
\chessboard[style=4x4,setwhite={Qd4}, pgfstyle=straightmove,
arrow=to,linewidth=0.2ex,
color=red,
pgfstyle=straightmove,
markmoves={d4-h8,d4-a7,d4-a1,d4-g1,d4-d8,d4-d1,d4-a4,d4-h4},
shortenstart=1ex,showmover=false]
\end{document}


• Use xskake instead. It's more flexible Sep 3, 2014 at 21:32
• Please think carefully about the titles you use for question. 'How to make this using the Latex?' could be anything: something like 'How do I show the queens problem using the chessboard package?' would be much better. Sep 4, 2014 at 5:56
• @skpblack: xskak and chessboard do different things and xskak actually loads and uses chessboard to print boards. Sep 4, 2014 at 13:37

Maybe a start:

\documentclass{standalone}
\usepackage[LSB,LSBC3,T1]{fontenc}
\usepackage{chessboard}
\storechessboardstyle{8x8}{%
maxfield=h8,
borderwidth=10mm,
boardfontencoding=LSBC3,
color=white,
colorwhitebackfields,
color=black,
colorblackbackfields,
whitepiececolor=yellow,
pgfstyle=border,
color=white,
markregion=a1-h8,
}
\begin{document}
\chessboard[
style=8x8,
setwhite={Qa8,Qb4,Qc1,Qd3,Qe6,Qf2,Qg7,Qh5},
pgfstyle=straightmove,
arrow=stealth,
linewidth=.5ex,
color=blue!75!white,
pgfstyle=straightmove,
shortenstart=1ex,
showmover=true,
markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3},
]
\end{document}


For straighter arrows:

\documentclass{standalone}
\usepackage[LSB,LSBC3,T1]{fontenc}
\usepackage{chessboard}
\usetikzlibrary{arrows.meta}
\makeatletter
\cbDefinePgfMoveStyle{mystraightmove}{%
\pgfsetlinewidth{\board@pgf@linewidth}%
\setlength\len@board@tempx{\dimexpr 0.1em + \board@pgf@shortenstart \relax}%
\pgfsetshortenstart{\len@board@tempx}%
\setlength\len@board@tempx{\board@pgf@shortenend}%
\pgfsetshortenend{\len@board@tempx}%
\pgfsetarrowsend{\board@pgf@arrow}%
\pgfsetrectcap
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfpointanchor{#1}{center}}%
\pgfusepath{stroke}}%
\makeatother
\storechessboardstyle{8x8}{%
maxfield=h8,
borderwidth=10mm,
boardfontencoding=LSBC3,
color=white,
colorwhitebackfields,
color=black,
colorblackbackfields,
whitepiececolor=yellow,
pgfstyle=border,
color=white,
markregion=a1-h8,
}
\begin{document}
\chessboard[
style=8x8,
setwhite={Qa8,Qb4,Qc1,Qd3,Qe6,Qf2,Qg7,Qh5},
pgfstyle=mystraightmove,
linewidth=.5ex,
color=blue!75!white,
arrow={Triangle[width=1.5ex, length=1ex]},
shortenstart=1ex,
shortenend=-.5ex,
showmover=false,
markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3},
]
\end{document}


I tried to figure out a way to wrap the arrows in a pgf transparency group so that I could make them partially transparent without weirdness. However, when I tried this, the arrows disappeared altogether and I couldn't figure it out.

• You can switch the opacity before markmoves and then back again: E.g. opacity=0.5, markmoves={d3-h7,d3-a6,d3-b1}, opacity=1, markmoves={d3-f1,d3-d8,d3-d1,d3-a3,d3-h3}, Sep 4, 2014 at 13:43
• @UlrikeFischer Thanks. There is no issue making the arrows partially transparent per se. However, I wanted to wrap them in a transparency group to avoid showing the way they are constructed. That is, if I just set the opacity to .5, say, then you can see where the line is made and how it crosses the arrow head. So I tried to use a transparency group so they would look uniform. I tried to put this in the definition of mystraightmove but I must have done it wrongly as the arrows disappeared completely when I did that.
– cfr
Sep 4, 2014 at 13:51